说
ExecutorService ex = Executors.newFixedThreadPool(nrofthreads);
安排一些工作,并在工作时等待。
However I have same Threadlocal objects in the worker-threads which need to be closed when the batch is done. Therefore, I would like to be able to call a custom close-method on all worker-threads created by the threadpool.
这样做的最合法方式是什么?
1. 现在是一 m,使用:
for(int i =0 ; i<20; i++){ //make sure to touch all threads with 20 runs..
ex.execute(new Runnable(){
public void run(){
tearDownThreadLocals();
}
});
}
ex.shutdown();
但是,这 t对我来说是很强的。
Thanks GJ