aspose file tools*
The moose likes Threads and Synchronization and the fly likes Multi threading problem in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Multi threading problem in Java" Watch "Multi threading problem in Java" New topic
Author

Multi threading problem in Java

Samruddhi Pimpalgaonkar
Greenhorn

Joined: Sep 21, 2006
Posts: 2
We are using Java 1.5.
I have a thread which is supposed to run throughout the life cycle of the application. It goes to sleep for sometime, wakes up and then performs certain operations on a resource. Now at the same time when this thread is operating on the resource, another scheduled thread gets spawned for this resource and performs another set of operation.

Now this 2nd thread is able to complete its operations. But the 1st thread is either hung/killed. We are not able to figure out what happened to the first thread.

Is there any way we can prevent the 1st thread from getting killed/hung when the 2nd thread comes up?
Is there a way to find on the machine what is the status of the threads on it when it has already reached this strange state?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Offhand I can't guess what the problem is here. Unfortunately this is one of those situations where by the time you have detected that there's a problem the useful diagnostic info has been lost. The best suggestion I can offer right now is: you need to identiry exactly where in your code did the first thread get killed/hung? Try adding some logging statements in between most/all statements in the existing code. When a thread gets killed or hung, you want to be able to look at a log file to see what was the last message from that thread before it died? What was it about to do? This sort of information is very useful when trying to debug problems such as you describe.


"I'm not back." - Bill Harding, Twister
Srikanth Raghavan
Ranch Hand

Joined: Oct 31, 2005
Posts: 389
Post a code snippet explaining your problem, try and recreate your problem to explain us. We may be able to solve it.

This is what I do most of the times and I solved most of the problems myself when I tried to create a self explanatory code snippet to post a question in the forums.

And don't forget to follow what Jim Yingst suggested.

Srikanth
Chris Hurst
Ranch Hand

Joined: Oct 26, 2003
Posts: 417
    
    2

What happens if you hit control break (Windows) or Unix equivalent does it give you the thread stack traces, to say where it was hung or if it was dead or does it not function in this scenario ? Never tried it haven't had a hung thread for a while (thank god)


"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Multi threading problem in Java