Loading
Thread Racing and Synchronizied

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  What is the Synchronizied Keyword ?, what is Thread Racing ?


  • Thread Racing and Synchronizied
    Sample Img 18

Ans)

A race condition occurs when the order of execution of two or more threads may affect
some variable or outcome in the program.
It may turn out that all the different possible
thread orderings have the same final effect on the application: the effect caused by the race
condition may be insignificant, and may not even be relevant.

Synchronized keyword can be applied to static/non-static methods or a block of code to make
your code Thread Safe.
Only one thread at a time can access synchronized methods and if
there are multiple threads trying to access the same method then other threads have to
wait for the execution of method by one thread. Synchronized keyword provides a lock
on the object and thus prevents race condition.

public void synchronized method(){} 
public void synchronized staticmethod(){}
public void myMethod(){
            synchronized (this){           
            }
}



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

Thread Racing and Synchronizied


Thread Racing and Synchronizied

-------------------------------------------------------------------------------------------------------



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free