PDF File
PDF File
Threod7..........
A Thread is a very lig ht—weig hted process or
we can say the smallest part of the
process that allows a prog ram to operate
more effi ciently by running multiple tasks
simuItaneously.
lmporatance:
A Thread is a very light-
weighted process, or wemore con
progroi
soy to
the smallest port of the
effi by allows
cient thot
operate
process running
a
tasks
ly multiple
Start •
{) , run(
New )
Thread()
Extending the Thread
class
I S in T e d
I Using start() method
MyThread thread - new
MyThread();
thread.start();
Difference between run() and
start()
methods.
• run(): Calls the code in the
current
thread.
• start(): Starts a new
• Purpose: To prevent data
inconsistency
in multi-threaded applications.
“ • Synchronized Block and Method:
Allows only one thread to access a
resource at a time.
CODE
Il
synchronized void myMethod() (
code
1 to
rity.