Module 2_Multithreading Part A
Module 2_Multithreading Part A
Module 2: Multithreading
If the thread is not assigned any priority, explicitly, then the default priority
value 5 is assigned to it.
There are 3 constants representing the minimum priority, default priority and
the maximum priority, which can be assigned to a thread. They are:
Similarly, if names are not provided to the threads being created, default
names are assigned for those threads (Thread-0, Thread-1, and so on).
The thread group by default is 'main' unless it is explicitly created.
Thilagavathi M, AP(Sr.), SCORE
Write a program to create 2 threads by implementing Runnable interface. The 2
threads must display the message "Hello" along with their thread name, priority and
group. class
Starts the thread in a separate path of execution, then invokes the run() method on this Thread
object.
2 public void run()
If this Thread object was instantiated using a separate Runnable target, the run() method is invoked
on that Runnable object.
3 public final void setName(String name)
Changes the name of the Thread object. There is also a getName() method for retrieving the name.
Sets the priority of this Thread object. The possible values are between 1 and 10.
5 public final void join( )
The current thread invokes this method on a second thread, causing the current thread to block until
the second thread terminates or the specified number of milliseconds passes.
6 public final boolean isAlive()
Returns true if the thread is alive, which is any time after the thread has been started but before it
runs to completion.
Thilagavathi M, AP(Sr.), SCORE
Static Methods of Thread Class
Sr.No. Method & Description