我正在使用线程池在不同的进程中运行任务,将所有线程连接到主线程,我正在做如下,但它需要更多的时间来给出结果。如何以有效的方式实现此目的。如何将线程连接到线程池中的主线程?
ExecutorService executor = Executors.newFixedThreadPool(2);
Runnable sendded = new com.treamis.hr.employee.Sendded(filePath, academicyearmaster);
executor.execute(sendded);
Runnable employeeAttendanceReport = new EmployeeAttendanceReport(filePath2);
executor.execute(employeeAttendanceReport);
executor.shutdown();
while (!executor.isTerminated()) {
}
System.out.println("Finished all threads");
用于执行程序的终止状态首先轮询是不对的。改用awaitTermination()方法。 就终止时间而言,取决于正在运行的任务停止的时间。你可以发布'EmployeeAttendanceReport'代码吗? – Kishore