我試圖做這個事情,但沒有得到如何執行?該代碼請求網絡服務發送短信帳單信息;記帳成功或失敗時記錄網絡服務的響應。 有時需要很長時間才能得到迴應,我想取消/暫停該進程並重新發送新的數字請求。的Java暫停處理,並與其他流
long before = System.currentTimeMillis();
String resp = new SmsConnection().doResponseRequest(sms);
long totalResponseTime=((System.currentTimeMillis() - before)/1000);
我只能記錄totalResponseTime
和某個需要50-100秒,得到服務的響應。有什麼辦法,我可以說
「如果resp
正在超過15秒取消/暫停此請求,並在同一時間重新發送另一個。我們收到的迴應後,我們將處理該請求。」
我需要的東西就像一個超時選項用於接收響應。請建議。
感謝,
你限於線程?爲什麼不使用它們,他們靈活且易於控制! – 2013-04-29 10:51:13