The setName() method assigns a name to a thread The start() method allocates the system resources. necessary to run the thread and executes the run() method of its target object[r]
(1)Session 1
(2)Advanced Java / Session1 / of 13
Module
Introduction to Thread
2 A Guide To Advanced Java – Module
(3)(4)Advanced Java / Session1 / of 13
(5)Creating Threads
Sub classing Thread
Creating subclass Overriding the run()
method
Starting the thread
Using the Runnable
interface
Implementing the
Runnable interface
Implementing the run()
method
(6)Advanced Java / Session1 / of 13
Thread states
(7)Methods of the Thread class
The getName() method helps to retrieve the name
of the current thread
The setName() method assigns a name to a thread The start() method allocates the system resources
necessary to run the thread and executes the run() method of its target object
The run() method contains instructions, which are
(8)Advanced Java / Session1 / of 13
Methods of the Thread class …
(9)(10)Advanced Java / Session1 / 10 of 13
Managing Thread
Thread priority
Thread.MAX_PRIORITY : constant value of 10
Thread.NORM_PRIORITY : constant value of 5, default Thread.MIN_PRIORITY : constant value of 1
Methods:
setPriority()
getPriority() A Guide To Advanced Java – Module 10
• Thread priority helps the thread scheduler to decide
which thread to run
• Priority also helps the OS to decide the amount of
(11)(12)Advanced Java / Session1 / 12 of 13
Needs for Daemon Thread
(13)