This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Synchronization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Synchronization" Watch "Synchronization" New topic


Iter Jugu

Joined: Jan 31, 2007
Posts: 1
I have a singleton class.
- In another class say A i get that singleton instance.
- Call a set method
- then start a thread which works on this singleton instance.

Now my problem is when one such thread is started and works on that instance another thread
is also started. this leads to sync problm.

This can be fixed using synchronization but this is not advisable as this thread has to contact a server.
Till this thread returns all other threads have to wait.

Please help me to solve this issue???
Chris Beckey
Ranch Hand

Joined: Jun 09, 2006
Posts: 116

We'll need to see some more detail but off-hand it sounds like you are synchronizing things that don't need to be synchronized.

1.) Is the singleton doing the server call?
2.) Does the state of the singleton need to be preserved for the length of the server call?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Or making a Singleton that shouldn't be. In the universe in general, there are many of those. Why must there be only one instance of this thing?

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Synchronization
Similar Threads
threadsafety of a singleton
A question about thread safety and servlets
Singleton Pattern - toClone
Question regarding Singleton pattern
Thread safety in the database access.