6262public class hs203t003 extends RedefineAgent {
6363
6464 public native boolean popThreadFrame (Thread thread );
65- public native boolean resumeThread (Thread thread );
65+ public native boolean isSuspended (Thread thread );
66+ public native boolean resumeThread (Thread thread );
6667
6768
6869 public hs203t003 (String [] arg ) {
@@ -82,21 +83,37 @@ public boolean agentMethod() {
8283 MyThread mt = new MyThread ();
8384 try {
8485 mt .start ();
85- // check if we can can pop the thread.
86- // we can not do redefine/pop frame on run method.
86+ // Check if we can can pop the thread.
87+ // We can not do redefine/pop frame on run method.
8788 while (!MyThread .resume .get ());
88- // sleep for some few secs to get redefined.
89+ // Sleep for some few secs to get redefined.
8990 while (!isRedefined ()) {
9091 if (!agentStatus ()) {
9192 System .out .println ("Failed to redefine class" );
9293 return passed ;
9394 }
9495 Thread .sleep (100 );
9596 }
96- popThreadFrame (mt ); // pop the frame.
97- resumeThread (mt ); // resume the thread.
97+ // Wait for the thread to be suspended.
98+ while (!isSuspended (mt )) {
99+ if (!agentStatus ()) {
100+ System .out .println ("Failed to suspend thread" );
101+ return passed ;
102+ }
103+ Thread .sleep (100 );
104+ }
105+ // Pop the frame.
106+ if (!popThreadFrame (mt )) {
107+ System .out .println ("Failed to pop a frame = "
108+ + mt .threadState );
109+ }
110+ // Resume the thread.
111+ if (!resumeThread (mt )) {
112+ System .out .println ("Failed to resume the thread = "
113+ + mt .threadState );
114+ }
115+ // Wait till the other thread completes its execution.
98116 mt .join ();
99- // wait till the other thread completes its execution.
100117 System .out .println ("Thread state after popping/redefining = "
101118 + mt .threadState );
102119 } catch (Exception ie ) {
0 commit comments