Professional Documents
Culture Documents
Multithreading: Mrs. Chavan P.P. 1
Multithreading: Mrs. Chavan P.P. 1
class MyThreadDemo
{
public static void main( String args[] )
{
MyThread mt = new MyThread();
Thread t = new Thread(mt);
t.start();
} Output :
} concurrent thread started running..
Mrs. Chavan P.P. 13
Extending Thread class
• This is another way to create a thread by a
new class that extends Thread class and
create an instance of that class.
• The extending class must
override run() method which is the entry
point of new thread.
classMyThreadDemo
{
public static void main( String args[] )
{
MyThread mt = new MyThread();
mt.start();
}
} Output :
concurrent thread started running..
Mrs. Chavan P.P. 15
Thread Priority
• Each thread have a priority.
• Priorities are represented by a number
between 1 and 10.
• In most cases, thread schedular schedules the
threads according to their priority (known as
pre-emptive scheduling).
• But it is not guaranteed because it depends on
JVM specification that which scheduling it
chooses.
Mrs. Chavan P.P. 16
Thread Priority
• 3 constants defiend in Thread class:
– public static int MIN_PRIORITY
– public static int NORM_PRIORITY
– public static int MAX_PRIORITY
• The value of Default priority i.e.
NORM_PRIORITY is 5.
• The value of MIN_PRIORITY is 1 and the value
of MAX_PRIORITY is 10.