Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Do I need to synchronize this method  RSS feed

 
Srivatsan Varadarajan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a class to retrieve a userid/password object. I want to store this value as a static variable so that its retreived only once. I am confused if synchronization is needed or will it not matter since the same value would be returned regarding of any thread accessing it. This is my class below. Is there any purpose achieved in synchronizing the getAppUser1 method?




 
Chris Beckey
Ranch Hand
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what you have shown, and assuming that there are multiple threads and one user (i.e. desktop app), the answer is yes.
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to sync it (or do something clever) , the code looks like you want getAppUser1 but you could have many depending on how its invoked ...

try reading this see if it helps

http://en.wikipedia.org/wiki/Double-checked_locking
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!