At the end of the day, they're all relying on the same underlying Thread -based mechanism to actually do the work. That means that if you are asking "what is the most efficient way to start a single thread? " the answer is, create a Thread object and call start() on it, because any other method will take some other steps before it eventually creates a Thread object and calls start() on it.
Up vote 2 down vote favorite share g+ share fb share tw.
There seem to be a number of different ways in which one can create threads (Runnable vs Thread class) and also ThreadPools. Are there any difference in terms of efficiency and which are the most efficient (in terms of performance) techniques for creating and pooling threads in Java? Java jvm link|improve this question asked 2 days agouser9971126585 63% accept rate.
5 It depends on your use case. – Jeffrey 2 days ago What do you need to do? – dash1e 2 days ago @dash1e, I am asking generally.
What are the different best scenarios per technique? – user997112 2 days ago 1 It is too generic, we can write an entire book about it :D – dash1e 2 days ago This question is too broad to be answered properly. Voting to close.
If you have a specific use-case, please feel free to ask again. But bear in mind that the best answer to a more specific use-case will most likely be "measure it yourself". – Stephen C 2 days ago.
At the end of the day, they're all relying on the same underlying Thread-based mechanism to actually do the work. That means that if you are asking "what is the most efficient way to start a single thread? " the answer is, create a Thread object and call start() on it, because any other method will take some other steps before it eventually creates a Thread object and calls start() on it.
That doesn't mean that this is the best way to spawn threads, it just means that it is the most low-level way to do it from Java code. What the other ways to create threads give you is different types of infrastructure to manage the underlying Threads, so your choice of method should depend on the amount and kind of infrastructure you need.
If you need to handle many short and frequent requests it is better to use a ThreadPool so you can reuse threads already open and assign them Runnable tasks. But when you need to launch a thread for a single task operation or instantiate a daemon thread that run for all the application time or for a long specific time then could be better create a single thread and terminate it when you don't need it anymore.
Sorry, I knew this much. I was basically asking is Thread faster than implementing Runnable and then, out of the ThreadPool techniques, how do they differ in terms of performance? – user997112 2 days ago The difference between extends a Thread or create one and assign a Runnable is trivial.
In the first case you create a java object and start the thread, in the second one you create Runnable, create a Thread with Runnable and start it. If the task that you process is not istant (end if you need launch a thread it is not) than the difference between two solutions is not important. – dash1e 2 days ago.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.