Lecture 16 - Multithreading
Lecture 16 - Multithreading
CSE 201
Lecture 16: Multithreading
Multithreading
❖ Every single thread created in Java has some priority associated with it.
❖ The programmer can explicitly assign the priority to the thread. Otherwise, JVM
automatically assigns priority while creating the thread.
❖ In Java, we can specify the priority of each thread relative to other threads. Those
threads having higher priorities get greater access to the available resources than
lower priorities threads.
❖ Thread scheduler will use priorities while allocating processor.
❖ The valid range of thread priorities is 1 to 10 (but not 0 to 10), where 1 is the
least priority, and 10 is the higher priority.
❖ If there is more than one thread of the same priority in the queue, then the
thread scheduler picks any one of them to execute.
❖ The following static final integer constants are defined in the Thread class:
● MIN_PRIORITY: Minimum priority that a thread can have. Value is 1.
● NORM_PRIORITY: This is the default priority automatically assigned by JVM to
a thread if a programmer does not explicitly set the priority of that thread. Value
is 5.
● MAX_PRIORITY: Maximum priority that a thread can have. Value is 10.
You can set
priority using
any number
between 1
and 10, not
just these
constants.
Introducing wait time
though Thread.sleep().