我的代码仍在工作,我可以发送消息并等待消息发送。发送消息的持续时间大约为 10 秒,这对我不利,因为我的程序在发送下一条消息之前需要 1 秒的间隔。看看以澄清问题。
msg4 -> msg3 -> msg2 -> msg1
msg4、msg3 和 msg2 仍在等待,直到 msg1 已发送/失败。
这是代码sendMessage.java
public void doIt(String mobile_number, String message) throws Exception
{
OutboundNotification outboundNotification = new OutboundNotification();
System.out.println("Example: Send message from a serial gsm modem.");
System.out.println(Library.getLibraryDescription());
System.out.println("Version: " + Library.getLibraryVersion());
SerialModemGateway gateway = new SerialModemGateway("modem.com5", "COM5", 921600, "", "");
gateway.setInbound(true);
gateway.setOutbound(true);
Service.getInstance().setOutboundMessageNotification(outboundNotification);
Service.getInstance().addGateway(gateway);
Service.getInstance().startService();
System.out.println();
System.out.println("Modem Information:");
System.out.println(" Manufacturer: " + gateway.getManufacturer());
System.out.println(" Model: " + gateway.getModel());
System.out.println(" Serial No: " + gateway.getSerialNo());
System.out.println(" SIM IMSI: " + gateway.getImsi());
System.out.println(" Signal Level: " + gateway.getSignalLevel() + " dBm");
System.out.println(" Battery Level: " + gateway.getBatteryLevel() + "%");
System.out.println();
OutboundMessage msg = new OutboundMessage(mobile_number, message);
Service.getInstance().sendMessage(msg);
System.out.println(msg);
System.out.println("Now Sleeping - Hit <enter> to terminate.");
// System.in.read();
Service.getInstance().stopService();
}
在我的main.java类中
for(int i=0; i<4; i++) {
new sendMessage().doIt("09483221***","This is the message");
Thread.sleep(1000);
}
第一条消息已成功发送,但第二条消息未发送,依此类推。如何让这些等到发送第一条消息?