MULTITHREADING IN JAVA
DR. P. JEYANTHI
ASSISTANT PROFESSOR,
DEPARTMENT OF INFORMATION TECHNOLOGY
SRI RAMAKRISHNA COLLEGE OF ARTS & SCIENCE
MULTITHREADED PROGRAMMING
INTRODUCTION
• A program that contains multiple flows of
control is known as multithreaded program.
• Figure 12.2 illustrates a Java program with four
threads, one main and three others.
• The main thread is actually the main method
module, which is designed to create and start the
other three threads, namely A, B and C.
• Once initiated by the main thread, the threads A,
B, and C run concurrently and share the resources
jointly
• The ability of a language to support multithreads
is referred to as concurrency.
• Since threads in Java are subprograms of a main
application program and share the same memory
space, they are known as lightweight threads
or lightweight processes.
• 'Threads running in parallel' does not really mean
that they actually run at the same time.
• Since all the threads are running on a single
processor, the flow of execution is shared between
the threads.
• The Java interpreter handles the switching of
control between the threads in such a way that it
appears they are running concurrently.
• Multithreading is a powerful programming tool
that makes Java distinctly different.
• It enables programmers to do multiple things at
one time.
• They can divide a long program into threads
and execute them in parallel
CREATING THREADS
EXTENDING THE THREAD CLASS
EXTENDING THE THREAD
CLASS
• Example Program
LIFE CYCLE OF A THREAD
LIFE CYCLE OF A THREAD
22323
22323
THREAD METHODS
THREAD PRIORITY