Synchronized

Mike Shn

Ranch Hand

Posts: 149

posted 15 years ago

What is the purpose of word synchronized in the function: public syncronized int endRead() { } Thanks

Dave Vick

Ranch Hand

Posts: 3244

posted 15 years ago

Mike The simple answer is that synchronized on an instance method means that when the method is executed a lock is aquired on the object associated with the method - the 'this' in the method. And that no other threads can execute synchronized code on that object until the lock is released. For more info check out the java tutorial section on threads and monitors.