Multi-Threading

                                 Multi-Threading

What is thread ?
Thread is a lightweight components and it is a flow of control. In other words a flow of
control is known as thread.

What is multithreading ?

Multithreading in java is a process of executing multiple threads simultaneously.

Explaing State or Life cycle of thread?
State of a thread are classified into five types they are
· New State
· Ready State
· Running State
· Waiting State
· Halted or dead State

How to achieve multithreading in java ?

In java language multithreading can be achieve in two different ways.
· Using thread class
· Using Runnable interface

In which state no memory is available for thread ?

If the thread is in new or dead state no memory is available but sufficient memory is
available if that is in ready or running or waiting state.

Difference between sleep() and suspend() ?
Sleep() can be used to convert running state to waiting state and automatically thread
convert from waiting state to running state once the given time period is completed.
Where as suspend() can be used to convert running state thread to waiting state but it
will never return back to running state automatically.

What is Thread Synchronization ?
Allowing only one thread at a time to utilized the same resource out of multiple
threads is known as thread synchronization or thread safe.

Why use Thread Synchronization ?

Whenever multiple threads are trying to use same resource than they may be chance
to of getting wrong output, to overcome this problem thread synchronization can be
used.

How to achieve Thread Synchronization in java ?
In java language thread synchronization can be achieve in two different ways.
· Synchronized block
· Synchronized method