Is there a concurrency structure (like a thread) in java which can execute runnables and be stopped and reexecuted, or do I have to implement it on my own?
java中是否存在可以执行runnables并且被停止和重新执行的并发结构(如线程),或者我必须自己实现它?
1 个解决方案
#1
0
ThreadPoolExecutor, example here.
ThreadPoolExecutor,这里的例子。
If, as Peter Lawrey suggested, you are after a reliable Runnable's lifecycle manager then Java is not the right tool. If a thread (or a task in an executor) hangs the best recovery behavior is to have a watchdog thread that will commit process suicide with "restart me" exit code and have an external launcher (shell script, etc.) to restart the process which dies with "restart me" exit code.
如果像Peter Lawrey建议的那样,你是在追求可靠的Runnable生命周期管理器,那么Java就不是正确的工具。如果一个线程(或执行程序中的任务)挂起最好的恢复行为,那就是有一个看门狗线程,它将通过“重启我”退出代码提交进程自杀,并有一个外部启动器(shell脚本等)来重启进程死了“重启我”退出代码。
#1
0
ThreadPoolExecutor, example here.
ThreadPoolExecutor,这里的例子。
If, as Peter Lawrey suggested, you are after a reliable Runnable's lifecycle manager then Java is not the right tool. If a thread (or a task in an executor) hangs the best recovery behavior is to have a watchdog thread that will commit process suicide with "restart me" exit code and have an external launcher (shell script, etc.) to restart the process which dies with "restart me" exit code.
如果像Peter Lawrey建议的那样,你是在追求可靠的Runnable生命周期管理器,那么Java就不是正确的工具。如果一个线程(或执行程序中的任务)挂起最好的恢复行为,那就是有一个看门狗线程,它将通过“重启我”退出代码提交进程自杀,并有一个外部启动器(shell脚本等)来重启进程死了“重启我”退出代码。