Topic: 小妹问个线程问题,各位ggjj帮忙 |
Print this page |
1.小妹问个线程问题,各位ggjj帮忙 | Copy to clipboard |
Posted by: xinzi Posted on: 2005-05-19 11:28 我有一个Job接口对象,Job执行时是创建一个实现Runnable接口的对象X,X会调用Job接口的execute()方法。但是Job这个方法可能长时间执行不完(由于某些异常)我想规定一个最大时间,如果超过这个时间则Job的execute()方法返回,并执行完X的run()方法,这样一个异常Job不会占用一个Thread过久。这个怎么实现? 小妹我查了很多资料,但无奈脑袋不开窍,没找到好的办法,请ggjj帮忙啊! |
2.Re:小妹问个线程问题,各位ggjj帮忙 [Re: xinzi] | Copy to clipboard |
Posted by: jigsaw Posted on: 2005-05-19 14:27 check javadoc of wait(long) and interrupt() of java.lang.Thread |
3.Re:小妹问个线程问题,各位ggjj帮忙 [Re: jigsaw] | Copy to clipboard |
Posted by: xinzi Posted on: 2005-05-19 16:31 Thanks for your advise jigsaw wrote: My code sketch is here, could you give me more suggestion pls. thanks a lot
|
4.Re:小妹问个线程问题,各位ggjj帮忙 [Re: xinzi] | Copy to clipboard |
Posted by: danzel Posted on: 2005-05-19 16:42 如果只是异常的话是不是可以考虑try{}catch??? |
5.Re:小妹问个线程问题,各位ggjj帮忙 [Re: xinzi] | Copy to clipboard |
Posted by: think Posted on: 2005-05-19 16:55 可以考虑后台运行一个定时器,timeout后终止正在运行的线程。 不过应该有许多的资源清除工作需要做。
|
6.Re:小妹问个线程问题,各位ggjj帮忙 [Re: xinzi] | Copy to clipboard |
Posted by: qizi Posted on: 2005-05-19 16:59 Job是一个interface 必须通过例如
|
7.Re:小妹问个线程问题,各位ggjj帮忙 [Re: xinzi] | Copy to clipboard |
Posted by: jigsaw Posted on: 2005-05-20 10:29
Note that Manager will NOT be interrupted if it's being blocked in IO opration. |
8.Re:小妹问个线程问题,各位ggjj帮忙 [Re: xinzi] | Copy to clipboard |
Posted by: henryevol Posted on: 2005-06-04 17:50 这个问题 jdk5.0 去 java.util.concurrent.* 里看看 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |