Unit-1 Topic 1.4 - Muthithreading - U
Unit-1 Topic 1.4 - Muthithreading - U
PROGRAMMING
Unit-1
Prepared By: Ms. Ankita Sharma
Assistant Professor
Department of Computer Science
GTBIT, GGSIPU
isAlive() The isAlive method is invoked to verify if the thread is alive or dead
The yield method is used to send the currently executing threads to standby
yield()
mode and runs different sets of threads on higher priority
The yield method is used to send the currently executing threads to standby
yield()
mode and runs different sets of threads on higher priority
suspend() The suspend method is used to instantly suspend the thread execution
resume() The resume method is used to resume the execution of a suspended thread only
destroy() The destroy method is invoked to destroy the execution of a group of threads
1. Synchronized Method
It is a method that can be declared synchronized using the keyword
“synchronized” before the method name.
By writing this, it will make the code in a method thread-safe so that no
resources are shared when the method is executed.
Syntax: synchronized public void methodName() { }
2. Synchronized Block
If a block is declared as synchronized then the code which is written
inside a method is only executed instead of the whole code.
It is used when sequential access to code is required.
Syntax: synchronized (object reference)
{
// Insert code here
}
3. Static Synchronization
The method is declared static in this case.
It means that lock is applied to the class instead of an object and only
one thread will access that class at a time.
Syntax: synchronized static return type class name{}
Wait Sleep
• The wait() method releases the • The sleep() method doesn't release
lock. the lock.
• It is a method of Object class • It is a method of Thread class
• It is the non-static method • It is the static method
• It should be notified by notify() or • After the specified amount of time,
notifyAll() methods sleep is completed.