Name: diC59631 Date: 12/15/97
When the debugee is stopped on a breakpoint, the
debugger api RemoteThread.cont() will resume all
threads including threads suspended in the user
code.
This means that the user's program flow is
affected by the debugger such that some programs
can not be debugged because their behaviour is changed
after stopping on a breakpoint.
I consider this a serious problem that stops this
debug api from debugging multi-threaded applications.
Example source code appears at the end of this note.
To reproduce using jdb:
1) add breakpoint anywhere in ThreadSuspend.main after
the 2nd thread has been suspended.
2) run ThreadSuspend
3) at the breakpoint enter "cont"
4) the 2nd thread will start printing messages again.
EXAMPLE SOURCE CODE:
class ThreadSuspend {
public static void main(String args[])
{
// Create the 2nd thread
TestThread t1 = new TestThread();
t1.start();
// sleep a bit to show that the 2nd thread is running
try {
Thread.currentThread().sleep(1000);
} catch( InterruptedException err ) {}
// now suspend the 2nd thread ... it should not print an more messages
t1.suspend();
System.out.println("2nd thread has been suspended");
// now loop and print out that the main thread is running
do {
System.out.println("In the main thread ");
try {
Thread.currentThread().sleep(1000);
} catch( InterruptedException err ) {}
} while(true);
}
}
class TestThread extends Thread {
public void run() {
do {
System.out.println("In thread" + getName());
try {
sleep(250);
} catch(InterruptedException e){};
} while(true); // forever
}
}
(Review ID: 21891)
======================================================================
- duplicates
-
JDK-4093006 sun.tools.debug API resumes threads suspended by debugee when single stepping
- Closed