Creation of threads can be done by using following two ways:
A class is created that extends the java.lang.Thread class. This class overrides the run() method which is a part of the Thread class. Life of a thread begins inside run() method. An object of the new class can be created and start() method can be called to start the execution of a thread. Start() invokes the run() method on the Thread object.
A new class is created which implements java.lang.Runnable interface and overrides run() method. A Thread object can be instantiated and call start() method on this object.
Knowledge2life outside thread
This code is running in a thread
Knowledge2life outside of the thread
This code is running in a thread
|