public?final?void?awaitRunning(long?timeout,?TimeUnit?unit)
南縣網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,南縣網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為南縣上千提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站建設(shè)要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的南縣做網(wǎng)站的公司定做!
waitForServiceToStop(long?timeout)
timeout?(ms),
你用哪個(gè)AbstractService包呢
WebService超時(shí)設(shè)置
1. 服務(wù)器端設(shè)置超時(shí)
在 web.config 的 system.web 里添加如下配置項(xiàng):
httpRuntime
executionTimeout="30"
/
以上時(shí)間單位是秒.
記得要把 web.config 的 debug 模式關(guān)閉:
compilation
defaultLanguage="c#"
debug="false"
/
2. 客戶端設(shè)置超時(shí)
在 WebService 的客戶端代理程序(用 wsdl.exe 生成)里設(shè)置 Request 超時(shí)時(shí)間, 單位是毫秒:
protected override WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest wr = (HttpWebRequest)base.GetWebRequest( uri );
wr.Timeout = 30*1000;
return wr;
}
java 1.5以上的Future類可以執(zhí)行超時(shí)處理。
jdk1.5自帶的并發(fā)庫(kù)中Future類中重要方法包括get()和cancel(),get()獲取數(shù)據(jù)對(duì)象,如果數(shù)據(jù)沒有加載,就會(huì)阻塞直到取到數(shù)據(jù),而 cancel()是取消數(shù)據(jù)加載。另外一個(gè)get(timeout)操作,表示如果在timeout時(shí)間內(nèi)沒有取到就失敗返回,而不再阻塞。
代碼如下:
import?java.util.concurrent.Callable;
import?java.util.concurrent.ExecutionException;
import?java.util.concurrent.ExecutorService;
import?java.util.concurrent.Executors;
import?java.util.concurrent.TimeUnit;
import?com.sun.corba.se.impl.orbutil.closure.Future;
import?com.sun.corba.se.impl.orbutil.threadpool.TimeoutException;
public?class?ThreadTest?{??
public?static?void?main(String[]?args)?throws?InterruptedException,??
ExecutionException?{??
final?ExecutorService?exec?=?Executors.newFixedThreadPool(1);??
CallableString?call?=?new?CallableString()?{??
public?String?call()?throws?Exception?{??
//開始執(zhí)行耗時(shí)操作??
Thread.sleep(1000?*?5);??
return?"線程執(zhí)行完成.";??
}??
};??
try?{??
FutureString?future?=?exec.submit(call);??
String?obj?=?future.get(1000?*?1,?TimeUnit.MILLISECONDS);?//任務(wù)處理超時(shí)時(shí)間設(shè)為?1?秒??
System.out.println("任務(wù)成功返回:"?+?obj);??
}?catch?(TimeoutException?ex)?{??
System.out.println("處理超時(shí)啦....");??
ex.printStackTrace();??
}?catch?(Exception?e)?{??
System.out.println("處理失敗.");??
e.printStackTrace();??
}??
//?關(guān)閉線程池??
exec.shutdown();??
}??
}
標(biāo)題名稱:java超時(shí)時(shí)間代碼 java超時(shí)代碼塊處理
當(dāng)前網(wǎng)址:http://muchs.cn/article16/hphedg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷、微信公眾號(hào)、標(biāo)簽優(yōu)化、品牌網(wǎng)站設(shè)計(jì)、定制開發(fā)、網(wǎng)站設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)