Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

About real synchronized applications  RSS feed

clojure forum advocate
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)??
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!