如何在使用ExecutorService技术开发的多线程环境中实现log4j。
详细信息: 我们以一个excel工作表作为输入,列出excel工作表中的任务,根据实例数量将列表分为多个小列表,最后在不同线程实例中运行每个子列表中的任务。每个线程实例将使用命令模式并按顺序执行列表中存在的所有任务。
必需的收藏: 我们如何才能将所有日志以序列化的方式附加到单个文件以及控制台中,这样从线程1开始的日志应该首先打印,直到结束为止。
到目前为止已尝试实施: MDC-无法正确实施。
try {
ExecutorService executor = Executors.newFixedThreadPool(inNoOfInstances);
for (int i = 0; i < inNoOfInstances; i++) {
List<LinkedHashMap<String, String>> subList = newPartitionList.get(i);
Runnable runner = new TaskRunner(subList, _userName, _passWord, _dbUsername, _dbPassword, globalScopeMap, scope,i);
executor.execute(runner);
Thread.sleep(1000);
}
executor.shutdown();
executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
while (!executor.isTerminated()) {
}