I am having a Spring-boot application which contains following:
1. REST-API
2. One thread running from start will execute one service BS (background service we can say)
Note: BS have code to create 10 child thread which runs asynchronously to get things done.
Requirement:
1. BS is independent thread which will run throughout the application with main thread.
2. Child thread : will be created in BS and will get collapsed in BS once things done.
Problem: My thread BS needs to sleep(or you can say in wait state) if no work is pending and get back(notify) as and when work come. For this, I have used traditional way wait...notify but while waiting BS thread, the 10 child threads are executing the same code which BS thread is executing. I think thread pool management is not handled properly.
Help appreciate
BS Thread : ThreadPoolTaskExecutor & CommandLineRunner with connection pool set to 1
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(1);
executor.setMaxPoolSize(1);
executor.setQueueCapacity(500);
executor.setThreadNamePrefix("BS Thread:");
executor.initialize();
return executor;
Child Thread : 10 threads created using following code:
ExecutorService service = Executors.newFixedThreadPool(10);
for (BSChildExecutor jobs : listOfJobs) {
service.submit(jobs);
}
service.shutdown();`