multithreading - exit from function if not return value within 30 seconds java -
i have java code send sms .
return delivery report within 15 seconds in many times.(but times not happened)
want stop sms sending functions if not give delivery report withing 15 seconds.
if u can, please give similar sample code or
give links should read that.
thank much...!
`
public string sendtest(string port ) { modemname = "huwawi"; bitrate = 115200; modempin = "0000"; smsc = "+94785000008"; try { outboundmessage msg; outboundnotification outboundnotification = new outboundnotification(); serialmodemgateway gateway = new serialmodemgateway(id, "com1", bitrate, modemname, "e17u-1"); gateway.setinbound(true); gateway.setoutbound(true); gateway.setsimpin(modempin); service.getinstance().setoutboundmessagenotification(outboundnotification); service.getinstance().addgateway(gateway); service.getinstance().startservice(); msg = new outboundmessage("+94710433607", "test successful !"); service.getinstance().sendmessage(msg); outboundmessage.messagestatuses status = msg.getmessagestatus(); system.out.println(msg.getmessagestatus()); service.getinstance().stopservice(); service.getinstance().removegateway(gateway); } catch (exception ex) { if (ex.getstacktrace()[2].getlinenumber() == 189) { joptionpane.showmessagedialog(null, "port owned usb modem's application. \n please close & run programm again.", "port exception", joptionpane.error_message); ex.printstacktrace(); } else { joptionpane.showmessagedialog(null, ex.getmessage(), "sending faile", joptionpane.error_message); ex.printstacktrace(); } }return port; }
`
if give wrong port number code stuck from
service.getinstance().startservice();
if give correct port number delivery report received before 15 seconds.
if give wrong port number,code doesn't give or return value. if code not return value within 15 seconds , know port number wrong one.
want close function automatically if not return value within 15 seconds.
again...!
you should make thread, , stop if nothing happen under 15s. mean :
thread t = new thread(){ @override public void run() { // send sms } } t.start(); // ... long time = system.currenttimemillis(); while(true) { if(system.currenttimemillis() - time > 15000) t.stop(); }
i hope said
Comments
Post a Comment