jeudi 12 mai 2016

Multithreading design decison for a complex scenerio

I have one complex multi-threading problem. I have list of tasks, lets say 50 task. Each task will have timeout period, and timeout may be different for each tasks. I want to execute all tasks parallely.

I will have thread pool of size let say 20. so this thread pool must take those many tasks that can be handled immediately. If only 10 threads are free then only 10 task should be picked by executor and I can get rejected task list. I means task should not go in any waiting queue. Because my application will be running in clustered environment, so other machines executor can pick remaining tasks. so one machine will not get overloaded.

I see few options available in java like ExecutorService.invokeAll(Collection> tasks, timeout). But It take same timeout period for all task. Also If any exception occurs in task execution then Executor don't pick any task and gets stuck.

Please suggest me some ready to use implementation in java or do I have to go with custom implementation.

Aucun commentaire:

Enregistrer un commentaire