Menu
Topics Index
...
`
Multi threading is one of the major feature of java programming, which means two or more parts of a program executing concurrently also effectively using resources. To do this we use threads. A thread is a single sequential flow of control within a program.


What is Multitasking and Multithreading?
Multitasking
In computing, multitasking is a method by which multiple tasks, also known as processes, share common processing resources such as a CPU. With a multitasking OS, such as Windows XP, you can simultaneously run multiple applications. Multitasking refers to the ability of the OS to quickly switch between each computing task to give the impression the different applications are executing multiple actions simultaneously.

Multithreading
Multithreading extends the idea of multitasking into applications, so you can subdivide specific operations within a single application into individual threads. Each of the threads can run in parallel. The OS divides processing time not only among different applications, but also among each thread within an application. Multithreading enables you to write in a way where multiple activities can proceed concurrently in the same program.
Life Cycle of a Thread
Thread undergoes different stages in its life time. The stages of the thread are as follows.
NEW
A thread that has not yet started is in this state.
RUNNABLE
A thread executing in the Java virtual machine is in this state.
WAITING
A thread that is waiting indefinitely for another thread to perform a particular action is in this state.
TIMED_WAITING
A thread that is waiting for another thread to perform an action for up to a specified waiting time is in this state.
TERMINATED
A thread that has exited is in this state.
A thread can be in only one state at a given point in time. These states are virtual machine states which do not reflect any operating system thread states.
NOTE:If getState() method is used to obtain the state of a thread.

Assigning Priorities To Thread: Suppose a process has a multiple no.of threads, it may be difficult for cpu to schedule these threads so, we can set priority to these threads which makes it easy for cpu to schedule these threads.
There are three priorities for a thread MAX_PRIORITY, MIN_PRIORITY and NORM_PRIORITY. NORM_PRIORITY is the default priority. Threads with higher priority should be allocated processor time before lower-priority threads. However, thread priorities cannot guarantee the order in which threads execute.

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App