Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronization

 
Iter Jugu
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic