java 多线程

@Log4j
public class SendSms extends Thread {
public SendSms() {
}

public void run() {
try {
Config config = new Config();
String host = config.get("smgwip");
String account = config.get("smgwaccount");
String passwd = config.get("smgwpasswd");
String spid = config.get("smgwspid");
String spnum = config.get("smgpspnum");
int port = Integer.parseInt(config.get("smgwport"));
String destnum = config.get("destnum");
String content = config.get("content");
String productid = config.get("productid");
Client client = new Client(host, port, 2, account, passwd, spid, 0);
Submit submit = new Submit();
submit.setSrcTermid(spnum);
submit.setDestTermid(destnum);
submit.setMsgContent(content.getBytes("iso-10646-ucs-2"));
submit.setMsgFormat(8);
if (productid != null) {
submit.setProductID(productid);
}

Result result = client.Send(submit);
log.info("Status:" + result.ErrorCode);
log.info("MsgID:" + result.ErrorDescription);
client.Close();
} catch (Exception ex) {
log.error("Error: " + ex.getMessage());
}
}

public static void main(String[] args) throws IOException {
for (int total = 0; total < 60; ) {
for (int count = 0; count < 2; count++) {
try {
SendSms sendSms = new SendSms();
sendSms.start();
total++;
Thread.sleep(1000);
} catch (InterruptedException ex) {
log.error("Ignore Error: " + ex.getMessage());
}
}
}
}
}
原文地址:https://www.cnblogs.com/dinglulu/p/5235509.html