Hello,
We have to be smart please, please look at the ThreadPoolExecutor Class of Java, look for example at the awaitTermination() method, it says:
---
boolean awaitTermination(long timeout, TimeUnit unit)
Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.
--
read more here:
Did you notice ?
In Java when you wait for the tasks you have to wait for "ALL" the tasks, and that's not efficient , and if you want to use the object from multiple threads i think it will have the same effect, you can avoid some of the problems by using many objects of the ThreadPoolExecutor class but this will take ressources and this will cause more and more context switches and that's bad, i think C# has the same problem, other than that Java and C# don't support priorities, it means that you can not give priorities to tasks/jobs, like high or normal or low, and that's not good for games and other applications where you have to use priorities even if the system is not a realtime system, this is why i have decided to implement my efficient Threadpool engine version 2.0 that supports those characteristics, so that you can create a child object of the Threadpool class that will use the same worker threads and that will wait only for the tasks that you will add with the execute() method , and also my efficient Threadpool engine supports 3 priorities, High and normal and low, that's where my efficient Threadpool engine comes in hand and that's where it's efficient. Hope you will like it.
And as you have noticed i have implemented an efficient Threadpool engine version 2.0, also what i want to say in this post, is that i have made it smart like a smart automaton with states and transitions that will guide you using exception handling so that to avoid the forbiden transitions. I have enhanced the automaton and i think that it's efficient now, please read the HTML tutorial inside the zip file to understand how to use the execute() and setCounter() and wait() methods etc.