A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Threads and Synchronization
Joined: Jan 31, 2007
Jan 31, 2007 01:57:00
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???
Joined: Jun 09, 2006
Jan 31, 2007 05:07:00
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?
Joined: Jan 29, 2003
Jan 31, 2007 06:44:00
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
I agree. Here's the link:
A question about thread safety and servlets
Thread safety in the database access.
Question regarding Singleton pattern
Singleton Pattern - toClone
threadsafety of a singleton
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014