Guys I'm in bit dilemma between Tree Set
and Thread Pool Executor
Following is the scenario :
First Approach
- I have to use structure which has tasks in it with priorities of each task.Now based on
treeset constructor
(withcomparator
interface) - I can compare task on priorities and based on that, tasks are ordered properly.
- Now after that, tasks should processed in order of priority through iteration of tree set and execute each task one by one.
Second Approach
- second approach is to do some sort of logic building and use core functionality of
Thread pool executor
and for this I had taken inspiration from this link and I had achieved my requirements with this approach also which will choose high priority task first and execute it first and same way it will execute all the tasks.
Now my confusion here is which one is best to use in term of performance costs, flexibility(increase/decrease threads) etc and why should I opt for it?
Any suggestions and answers are highly appreciated.
Finally got the real winner out of this two. I should select for
Thread pool Executor
because of following reasonsthread pool executor
architecture and vice versa.comparator
interface though it has complexity O(logn) but after that we have to fetch it and it will become a sequential flow of single source so we will not multi-threaded environment advantage.etc were the reasons which I pointed out during a heavy brain storming,googling and last but not the least stack Overflow searching. Thank you all for your humble support and huge appreciation to @didierc for getting me clear over it.