I use ExecutorService displays an error

java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@19fc62cb rejected from java.util.concurrent.ThreadPoolExecutor@2a921aa8[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0] 

run in a cycle

  final ExecutorService exService = Executors.newSingleThreadExecutor(); for (String fileName : files) { createFile(filename); } exService.shutdown(); public void createFile(String name){ exService.submit(new Thread() { @Override public void run() { .......... } } 

What can be wrong

  • one
    may be that you turn off the ExecutorService (exService.shutdown ()) as soon as you have queued your tasks? - Vladyslav Matviienko
  • one
    and in general it is not clear why creating new threads, if you need to transfer Runnable to exService.submit () - Vladyslav Matviienko
  • so that they are executed in a separate thread in turn and not immediately - J Mas
  • one
    I do not see the connection of what you want to be with what you are doing. - Vladyslav Matviienko
  • but doesn’t it matter here that I’m passing because it is still inherited from Runnable - J Mas

0