Java Threads
Hiya, just wondering if anyone could tell me how to create a thread pool (by implementing Runnable) of say 20 threads executing task T ?
Thanks in Advance. I would be looking for actual code not explanation :-) plk |
Homework? :) Either way, this is not exactly what you are looking for, but it is easy to modify. You can pass as many threads as you wish as parameters in the ThreadPoolTest class.
Code:
import java.util.LinkedList; Code:
public class ThreadPoolTest { Regards! |
Kinda Homework :-)
Exam on Wednesday and I kinda missed the lectures on thread pools. I can see that here threads are creating by extending the Thread class, I've been told that its a bad practice, and that its better to implement the Runnable interface, I guess that it does not make any big difference for my level application codes but we've been told to implement Runnable as a good coding practice. Anyway thanks for this code. :-) Back to cramming ..... :study: plk |
You're welcome.
Now, extending a class or implementing an interface is often one of the funniest discussions one can have with Java and it can easily lead to a flamebait, so I'm not touching that with a sixty foot pole :D. But you may want to read an article about that: http://www.javaworld.com/javaworld/j...-abstract.html Regards! |
You can extend only one class so that's why implementing is better. :D
|
true :-) thats what we've been told :-)
Anyway, that article is pretty good :-) plk |
All times are GMT -5. The time now is 09:20 PM. |