Meaningless Drivel is fun!
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Multi threading problem in Java" Watch "Multi threading problem in Java" New topic

Multi threading problem in Java

Samruddhi Pimpalgaonkar

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

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.

Chris Hurst
Ranch Hand

Joined: Oct 26, 2003
Posts: 443

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
I agree. Here's the link:
subject: Multi threading problem in Java
jQuery in Action, 3rd edition