Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

synchronizing method calls

Status
Not open for further replies.

carpeliam

Programmer
Mar 17, 2000
990
US
I'm writing a class for interacting with a database. I want to make sure that a call to select() can not be made while a call to delete() is being made (ie, no two methods of the class should be called at once by seperate processes.) How do I do that? Liam Morley
lmorley@wpi.edu
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."
 
Hi Liam,

I think you should find that it's as simple as putting the keyword 'synchronized' in front of the methods names - what you are trying to achieve doesn't require anything more sophisticated.

That will mean that anything calling the method will get the object lock, and only release it when the method exits.

Chris
 
synchronized methods only prevent more than one thread from accessing the same method at the same time, not another method. you will have to define the class a synchronized, not 100% sure about that, or set up a flag to prevent access to other methods
 
sorry, Chris is correct. once one synchronized method is called with in an object, all other synchronized methods are also locked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top