Hi. I have developed a Teller swing application (modifying user's balance and ...). in this application, I have a modifyBalance( ) method that modifies user's balance. in the real world (where there are many tellers), should I declare modifyBalance( ) with the synchronized keyword (to be sure about data integrity)??
That probably depends on what class modifyBalance() is in. If it's in a Teller class, then synchronizing on the Teller won't help you much - because two different Tellers will still be able to acto concurrently, and that's the problem in this case - you don't want them accessing the Balance simultaneously. But if modifyBalance() is in the Balance class, then synchroning that method will probably help ensure data integrity - because only one synchronized method of a given Balance may run at once, regardless of which Teller is calling the method. It's hard to say more here without more details about the system. [ February 20, 2004: Message edited by: Jim Yingst ]
"I'm not back." - Bill Harding, Twister
Evacuate the building! Here, take this tiny ad with you:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database