Java Module5 v0.1
Java Module5 v0.1
Threads
CHANNAVEERAYA WM
Assistant Professor, Department of CS&E
The National Institute of Engineering, Mysuru
linkedin.com/in/channaveeraya-wujjini-matada-9323618
(Ex HCL-Perot Systems, Ex Siemens, Ex CSR(Qualcomm), Ex Dell, Ex Ericsson, Ex Ambient
Scientific Inc )
Note: Refer page 251 of “The Complete Reference” for more theory for the above,
Note: Refer page 253 of “The Complete Reference” for more theory for the above,
18-02-2024 NIE 3rd Sem- CSE-D & CSE-AIML - CHANNAVEERAYA WM 10
Threads in Java - Extending Thread Class
• Define a subclass that extends from the superclass Thread.
• In the subclass, override the run() method to specify the thread's operations,
(and provide other implementations such as constructors, variables and
methods).
• A client class creates an instance of this new class. This instance is called a
Runnable object (because Thread class itself implements Runnable interface).
• The client class invokes the start() method of the Runnable object. The result
is two thread running concurrently – the current thread continue after invoking
the start(), and a new thread that executes run() method of the Runnable
object.
https://www3.ntu.edu.sg/home/ehchua/programming/java/j5e_multithreading.html
• The wait() and notify() methods provide a way for a shared object to pause a
thread when it becomes unavailable to that thread and to allow the thread to
continue when available.