Forums Register Login

Do I need to synchronize this method

+Pie Number of slices to send: Send
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?




+Pie Number of slices to send: Send
From what you have shown, and assuming that there are multiple threads and one user (i.e. desktop app), the answer is yes.
+Pie Number of slices to send: Send
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
Uh oh, we're definitely being carded. Here, show him this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 707 times.
Similar Threads
Static variable initialization
Problem with save data in XML format
Synchronization Problem whil accessing JDBC Code
Doubt in Action Form
Legacy upgrade from JBOSS 3.2.3 to 4.2.2 resulting in null pointer errors
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 15:34:30.