java eclipse can't step through thread after breakpoint with multithreaded program

945 Views Asked by At

I have a program that has 4 worker threads operating on a method. If I place a breakpoint in the method each worker thread will pause on it but the step into and step over buttons (as well as play/pause/terminate) are disabled so I can't walk through the execution path.

I have tried using suspendVM rather than just suspending thread and just suspending one thread by using a conditional breakpoint referencing worker1 thread name but it makes no difference, the step in/over buttons are disabled

Anybody know how to get this to work? Its works fine when i'm running only a single main thread.

2

There are 2 best solutions below

1
daedalus On BEST ANSWER

Well I got it working but don't ask me how, I think it has something to do with native methods. If my thread suspends while there is a key next to the method (in the call stack) I can't use step buttons, but if its three blue bars in call stack I can. It seems to be pot luck which one I get so I just restart the program until I get lucky.

0
bluearrow On

I find the reason is my thread is blocked by my code. For example:

pulic void methodA(){
    ...
    methodB()
    ...
}

public void methodB{
    ...
    while(true){// it can be some other reason to block this thread
        Thread.sleep(100);
    }
    ...
}

If we F6(step over) in methodA, the thread status will be "stepping", and step in, step over and step return button status is disabled.