Cha*_*bon 4 java multithreading threadpool
我有一个预定的执行程序将参数重置为 0 并唤醒所有活动线程以继续处理。但是,在线程初始运行后,它不会再次执行。
ScheduledExecutorService exec = Executors.newScheduledThreadPool(4);
exec.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
logger.info("Setting hourly limit record count back to 0 to continue processing");
lines = 0;
executor.notifyAll();
Thread.currentThread().interrupt();
return;
}
}, 0, 1, TimeUnit.MINUTES);
Run Code Online (Sandbox Code Playgroud)
类中定义了另一个 Executor 来执行进一步的进程,但不确定这是否会影响它:
ExecutorService executor = Executors.newCachedThreadPool();
for (String processList : processFiles) {
String appName = processList.substring(0,processList.indexOf("-"));
String scope = processList.substring(processList.lastIndexOf("-") + 1);
logger.info("Starting execution of thread for app " + appName + " under scope: " + scope);
try {
File processedFile = new File(ConfigurationReader.processedDirectory + appName + "-" + scope + ".csv");
processedFile.createNewFile();
executor.execute(new APIInitialisation(appName,processedFile.length(),scope));
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
从文档中ScheduledExecutorService.scheduleAtFixedRate():
如果任务的任何执行遇到异常,则后续执行将被抑制。
因此,您的任务中的某些内容正在引发异常。我猜的号召executor.notifyAll()这是记录抛出IllegalMonitorStateException:
如果当前线程不是此对象监视器的所有者。