我有这样的方法:的ThreadPoolExecutor返回null
public class NFeRoboServiceImpl implements NFeRoboService {
private static volatile ThreadPoolExecutor executor;
private ThreadPoolExecutor getExecutor() {
if (executor == null) {
synchronized (NFeRoboServiceImpl.class) {
if (executor == null) {
executor = new ThreadPoolExecutor(2, 10, 10, TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(100, true), new RetryRejectedExecutionHandler());
Monitor monitor = new Monitor(nFePersistenceService, executor, 3);
Thread monitorThread = new Thread(monitor);
monitorThread.start();
}
}
}
return executor;
}
}
这个问题很奇怪,当我把光标移到新的ThreadPoolExecutor后的“执行者”,它说的是,对象为空,当我选择执行者和ctrl + 转变 + i,它显示我创建的对象。
我具有线程执行空:
getExecutor().execute(worker);
'executor'是一个静态字段吗?这听起来像这是至少有点特定于IDE。你在用什么IDE? – Michael
Im使用eclipse – AgamenonD2
你是**绝对**不使用“双重检查锁定”的有效**版本。有关选项,请参阅https://www.securecoding.cert.org/confluence/display/java/LCK10-J.+Use+a+correct+form+of+the+double-checked+locking+idiom。 – GhostCat