java multithreading tutorial

Bodhak java multithreading tutorial we are going to cover in detail about Multitasking, Advantages of multitasking, Process-based multitasking, Thread-based multitasking, What is the thread?, Advantages of the thread, Different ways of creating a thread.

thread class, Runnable interface, thread life cycle, thread scheduler, What is the difference between preemptive scheduling and time slicing, can we start a thread twice, Calling run method explicitly, thread interrupted methods like sleep,  join, yield and may more topics.


java multithreading tutorial

This topic is very important in terms of interview and for real-time applications.


The ability to execute more than one task at the same time, a task being a program.

The terms multitasking and multiprocessing are often used interchangeably, although multiprocessing implies that more than one CPU is involved.

In multitasking, only one CPU is involved, but it switches from one program to another so quickly that it gives the appearance of executing all of the programs at the same time.

Advantages :

Data can be copied and moved between programs.

More productive, since dozens of the different program can be running at once.

Disadvantages :

Requires more system resources.

What is the thread?

Need to handle concurrent processes

Definition:  Single sequential flow of control within a program

For simplicity, think of threads as processes executed by a program

Thread Class:

The java.lang.Thread class is a thread of execution in a program. The Java Virtual Machine allows an application to have multiple threads of execution running concurrently. Following are the important points about Thread:

Every thread has a priority. Threads with higher priority are executed in preference to threads with lower priority

Each thread may or may not also be marked as a daemon.

There are two ways to create a new thread of execution. One is to declare a class to be a subclass of Thread and,

the other way to create a thread is to declare a class that implements the Runnable interface

Next Page