我有一个班级组织如下:
public class MyClass {
ExecutorService pool;
public MyClass(){
pool = ... //inited by a class that implements ExecutorService
}
public final void submit(Runnable run){
pool.execute(run);
}
}
该方法是submit
线程安全的还是我应该使用Lock
基于 - 的系统?例如
ReentrantLock look = new ReentrantLock();
public final void submit(Runnable run){
lock.lock();
try{ pool.execute(run); } finally{lock.unlock();}
}