I have initialized a exectuor service with N threads. After the N threads finishes i want to wait for a while and then reuse the executor with new instance of N threads. How do i do this?
Here is the sample code i am using that is failing:
int NumberOfThreads=Integer.parseInt(PropertyHandler.getProperty("numberOfThreads")); ExecutorService executor = Executors.newFixedThreadPool(NumberOfThreads); log.info("Executor class has been initialized"); while (true) { jobStack = MrMestri.buildJobs(); log.info("Creating a job stack of the search urls"); if (jobStack.isEmpty()) { Thread.sleep(10000); } else { int jobToken = 0; while (jobStack.size() > 0) { jobToken++; MrRunnable worker = new MrRunnable(jobStack.pop()); executor.execute(worker); if (jobToken% Integer.parseInt(PropertyHandler.getProperty("totalTrends")) == 0) { log.info("All jobs for the clock cycle complete , waiting for next clock cycle to start. Number of jobs completed " + jobToken); executor.shutdown(); Thread.sleep(milliseconds); } Now that i am using executor shutdown , there is no executor to execute my threads. And my threads implement runnable.
Any quick response would be of great help. Thank you.