In Java I have a web service that starts some long running processes on different threads so that I can return a http status without the connection timing out.
My question involves creating a single long running thread that will simply run the ExecuterCompletionService.take.get() to get the threads that have completed and finish the processing of them.
will it be ok to run get the finished objects in that separate thread if the completion service is created in the main thread?
EG.
MainThread
- Create Completion service
- Accept requests and create long running process
- submit the Callable to the completion service
- If everything went well return HTTP status of 200
Monitor Thread
- Store a reference to the Completion service created in the Main thread.
- run completionservice.take.get()
- Generate report for completed task
- repeate
Is there anything special I need to worry about that I have overlooked? Like synchronizing issues. I know internally the completion service uses a blocking queue.