I would like to know what are the differences between each of the following implementations for threads, and when should I use each option.
1- Implementing Runnable
public class ClientThread implements Runnable
{
new Thread(this).start();
public void run()
{...}
}
2- Extending Thread
class ServerThread extends Thread
{
this.start();
public void run()
{...}
}
3- Worker Threads and SwingWorker which I’m really not familiar with…
Thank you very much
- Hi I’ve added another question in this matter below, it was published as an answer cause
I accidentally erased my cookies in the web browser thanks..
Okay guys thanks for all the info..
But, what should I use if I want to implement a count down timer for swing game which will run on screen parallel to the game without blocking the flow of the game because of the consistent timer in the background which will be shown there and probably will need to be run on the event dispatch thread…
Can I use the Runnable implementation or I must use swing worker?
Runnableinstance) and the job of managing the thread (theThreadinstance), and also allows to have theRunnablebe a subclass of something elseSwingWorkeris a class designed to implement a worker tread in a Swing application. It offers an API for the worker thread to communicate its status to the Swing event thread so that it can e.g. update a progress bar.Note that it’s generally very hard to work with threads manually. If you need multiple threads for performance reasons, it’s much better to work with a thread pool via the
Executorsclass.