Java thread synchronization and types
what is synchronization how it work short explanation?
synchronization is a technique through which we can control multiple thread execution at a time.
If you apply the synchronization concepts on the thread instruction, automatically whatever the thread is executing the instruction, that thread will be in a lock procedure so that no other thread will interrupt this thread.All remaining thread will wait for until the running thread is completed.
synchronization can be achieved in three way
Synchronized keyword —> Applied for method
As a prefix to the method in which statements written to be executed as a thread.
synchronized block —> Applied for inside the method
This should be applied inside the method,If we want to restrict this synchronization
for a few lines in a method.
Syntax
synchronization(this){
Statements
}
synchronized static block ---> Applied for method
Syntax
Synchronization static return type method name{
Statements
}
Comments
Post a Comment