• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multi threading problem in Java

 
Samruddhi Pimpalgaonkar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Srikanth Raghavan
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic