[ July 22, 2005: Message edited by: Richard Anderson ]
Originally posted by Richard Anderson:
I think it might be a good idea to use synchronized methods on database operations like updates. Think about it...you wouldn't want two people updating the same row at the same time because you run the risk of one person having inaccurate data.
I respectfully disagree. Yes, it's definately important to make sure that no two threads can modify the same record at the same time, but this taks is much better left to your DBMS than to a bit of ad-hoc written Java code. DBMS vendors have invested countless hours and dollars in working out an efficient and secure locking scheme; this is their bread-and-butter, their very reason for existing. Don't think for a moment you can do better by putting a synchronized keyword here and there, you're wildly underestimating the difficulties you'll run into. Randomly tagging java methods with the synchronized keyword is a very quick way of killing any and all performance of your Java application.
Put your database updates in a relational transaction and leave record locking to the DBMS. That's what it's for.
Originally posted by Mohen Vijay:
I have a static method that instantiates an object. If more than one person accesses the method, will it be an issue ??
Any help will be appreciated ...
That fully depends on the implementation of the static method. If the static method only accesses variables on the stack, you'll be fine. If the method does r/w access on any static variables or shared resources, you might get into trouble. Without a code fragment, it's impossible to say.
The key issue here, as Ulf Dittmer pointed out, is shared resources. That's where you might run into trouble. Two threads executing the same method per se is no cause for concern.
[ July 24, 2005: Message edited by: Barend Garvelink ]