aspose file tools*
The moose likes Threads and Synchronization and the fly likes Race condition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Race condition" Watch "Race condition" New topic
Author

Race condition

Farouk Mohamed1
Ranch Hand

Joined: Jul 26, 2001
Posts: 113
Hi
I am using JProbe Thread Analyser to investigae threading uses with my code.
I am running a swing application and when i start my application
my main method starts a thread which using a getter method which writes or initializes certain variable(resource) using lazy instantiation meaning(if null then create else return existing instance)
The other threads reads the same variable using the same getter method.
What i found is the Data race conditions are detected by Jprobe for these kind of lazy instantiated variables can you please tell me what should i do to avoid these conditions. I tried to synchronize that method that dint work either please anyone explain what is going on
Appreciate your help
Please guys
Reply soon
Farouk
Jim Baiter
Ranch Hand

Joined: Jan 05, 2001
Posts: 532
This sounds like a singleton, not lazy instantiation. Lazy instantiation would be where I partially construct an object and initialize the parts only when required. Are the threads altering the state of this singleton?
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
I have used JProbe Threadalyser, too. I found that it complained about all sorts of things that I was pretty sure were not problems. For instance, it considers it a Data Race problem if the outcome of my code can vary in any way depending on which of several contending threads happens to get a particular lock. However, I know that, in many of these cases, this variance of outcome is harmless.
Some of the conditions that JProbe complained about were genuine instances of threading problems that could have had undesirable effects, but had not been spotted in any code reviews or the like. Therefore, it is a useful tool. But unfortunately, it seems that you have to process a lot of false alarms to catch the real problems.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Farouk Mohamed1
Ranch Hand

Joined: Jul 26, 2001
Posts: 113
I agree with peter and i am sure that is what is happening
and for that matter i cannot synchornize all the code and use
wait and notify.
Peter by the way i want to test threading problems between a swing client application and RMIServer application and how do i test this any ides please using JProbe. If i start client application when server application is running it first asks me to stop server and then start client and i want JProbe to thread analyzer to investigate client and server simultaneously.
Please helpPPPPPPPPPPPPPPPPPPPPPPPPPPp
I disagree with jim baiter as it is not a singleton and a singleton needs a static instance
Thanks for your response and i think i am on the right track.
Farouk
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
I don't think one session of JProbe can analyse two processes at once. You may be able to run two JProbe sessions at once, one for client and one for server.
JProbe will only detect race conditions within the threads of one Java process. If you have problems with race conditions associated with the order of processing of messages between client and server, then I think that's an issue of application design. I do not know of a tool to assist here, although that doesn't mean none exists (I'd be interested to know if one does exist).
Using JProbe on any one process, I know of no way to ensure that it only detects "real" threading problems. You just have to wade through all the potential problems that it detects, work out what is happening, and decide for yourself which, if any, represent real problems.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Race condition
 
Similar Threads
Memory Profiling using JProbe with Weblogic
JProbe Error: Unable to instrument for line profiling
Need help with synchrnoized/wait/notify mechanism!
JProbe-examples
Using annotation to put unique value in output