-------------------------METHODS IN THREAD CLASS-------------
Before we begin with the programs(code) of creating threads, let’s have a look at
these methods of Thread class. We have used few of these methods in the example
below.
•getName(): It is used for Obtaining a thread’s name
•getPriority(): Obtain a thread’s priority
•isAlive(): Determine if a thread is still running
•join(): Wait for a thread to terminate
•run(): Entry point for the thread
•sleep(): suspend a thread for a period of time
•start(): start a thread by calling its run() method
Methods: isAlive() and join()
•In all the practical situations main thread should finish last else other threads
which have spawned from the main thread will also finish.
•To know whether the thread has finished we can call isAlive() on the thread
which returns true if the thread is not finished.
•Another way to achieve this by using join() method, this method when called
from the parent thread makes parent thread wait till child thread terminates.
•These methods are defined in the Thread class.
•We have used isAlive() method in the above examples too.
-------------------------METHODS IN THREAD CLASS-------------
•isAlive() method is used to determine if a thread is still alive. It is the best way
to determine if a thread has been started but has not yet completed its run()
method. final boolean isAlive();
•The nonstatic join() method of class Thread lets one thread “join onto the end”
of another thread. This method waits until the thread on which it is called
terminates. final void join();