Ask a Question
Advertise on boostr.in
Synchronization of Threads of java
In many cases concurrently running threads share dataÂ and two threads try to do operations on the same variables at the same time. This often results in corrupt data as two threads try to operate on the same data.
A popular solution is to provide some kind of lock primitive.Â Only one thread can acquire a particular lock at any particular time. This can be achieved by using a keyword â€śsynchronizedâ€ť .
By using the synchronize only one thread can access the method at a time and a second call will be blocked until the first call returns or wait() is called inside the synchronized method.
May 26, 2015
to add a comment.
Your name to display (optional):
Email me at this address if my answer is selected or commented on:
Email me if my answer is selected or commented on
Privacy: Your email address will only be used for sending these notifications.
To avoid this verification in future, please