1

I'm trying to debug a multithreaded app in Eclipse. There are 3 Threads

Read Write Controller

Read and Write both access a method in Controller. I am trying to debug a problem when Write executes that Controller method.

I've got a breakpoint set in the Write thread and the Controller. I break in Write and I turn off my network connection to simulate my error and hit resume so I wind up at my breakpoint in Controller.

When I'm there Controller works as it should: it kills the Read and Write threads (I think) and starts new Read and Write threads. After killing Read and Write, I turn on my network connection to simulate the problem being solved.

All this is great. What should happen now is everything continues on its merry way. Except what really happens is the Read thread executes and I wind up hitting the breakpoint I set in Controller again - the same one I previously hit from Write. To make matters worse, it still thinks the network connex is unavailable - which makes no sense as I've re-enabled it.

This all makes me wonder if I need to stop the Read thread from executing somehow. Do I need to suspend it via Eclipse? Is it even possible to kill a thread from an app running in the debugger?

Mark

user1126515
  • 1,133
  • 3
  • 17
  • 34

1 Answers1

0

Do I need to suspend it via Eclipse?
No there is no need to suspend a thread in order that you code works. I suspend rarely I thread, I do it when I suspect that is waiting for something I don't except. I use breakpoints to control the stop and sometimes with properties. Here is an interresting answer.

Is it even possible to kill a thread from an app running in the debugger?
No and if it was possible, it will not be a good idea regarding the current specifications of Java. A good method to stop a thread is to use a flag to exit from the run() method properly : see here

Are you sure that you exit from you Read and Write threads ? One way is to add debug info in you run method :

run()
{
  System.out.println("start : " + this.getName());
  // do your process
  System.out.println("stop : " + this.getName());
}

Logging is sometimes easier than debugging in multithreading. It is difficult to be more specific without the code.

Community
  • 1
  • 1
mki
  • 635
  • 3
  • 10