如何在ThreadPoolExecutor中重新生成线程?

时间:2019-05-24 07:30:39

标签: java multithreading

有没有办法让threadPoolExecutor监视线程并在达到超时阈值时重新生成它?

例如

ThreadPoolExecutor myThreadPool = new ThreadPoolExecutor(1, 1,
            10L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>(1000));

myThreadPool.submit(new MyTask());


public MyTask() {

}

@Override
public void run() {
    try {
        // do something, this sometimes hangs, how do thread communicate to myThreadPool that it needs to be respawn?
    } catch (Exception e) {

    }

0 个答案:

没有答案