I have a controller in which I am using future interface and creating 5 threads in threadpool. This controller is called by an ajax call. When I call this controller the first time it runs fine but if I make the request again it shows the exception below.
java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@1cbbac9 rejected from java.util.concurrent.ThreadPoolExecutor@53ee53[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 5]
I am posting code how I am calling the tasks.
private static final ExecutorService threadpool = Executors.newFixedThreadPool(20);
FactorialCalculator task1 = new FactorialCalculator("A");
FactorialCalculator task2 = new FactorialCalculator("B");
FactorialCalculator task3= new FactorialCalculator("C");
FactorialCalculator task4 = new FactorialCalculator("D");
FactorialCalculator task5= new FactorialCalculator("E");
System.out.println("Submitting Task ...");
Future future1 = threadpool.submit(task1);
Future future2 = threadpool.submit(task2);
Future future3 = threadpool.submit(task3);
Future future4 = threadpool.submit(task4);
Future future5 = threadpool.submit(task5);
System.out.println("Task is submitted");
In first request it is running all tasks- A,B,C,D and E but when I make request again it prints submitting tasks but doesn't print Task is submitted. Can someone help out what am I doing wrong.