| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package art; |
| 18 |
|
| 19 |
import java.util.Arrays; |
| 20 |
|
| 21 |
public class Test1907 { |
| 22 |
public static final Object lock = new Object(); |
| 23 |
|
| 24 |
public static void waitFor(long millis) { |
| 25 |
try { |
| 26 |
lock.wait(millis); |
| 27 |
} catch (Exception e) { |
| 28 |
System.out.println("Unexpected error: " + e); |
| 29 |
e.printStackTrace(); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
public static void waitForSuspension(Thread target) { |
| 34 |
while (!Suspension.isSuspended(target)) { |
| 35 |
waitFor(100); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
public static void run() { |
| 40 |
synchronized (lock) { |
| 41 |
Thread thrd = new Thread( |
| 42 |
() -> { |
| 43 |
try { |
| 44 |
|
| 45 |
System.out.println("Suspend self twice returned: " + |
| 46 |
Arrays.toString( |
| 47 |
Suspension.suspendList(Thread.currentThread(), Thread.currentThread()))); |
| 48 |
} catch (Throwable t) { |
| 49 |
System.out.println("Unexpected error occurred " + t); |
| 50 |
t.printStackTrace(); |
| 51 |
Runtime.getRuntime().halt(2); |
| 52 |
} |
| 53 |
}, |
| 54 |
"TARGET THREAD"); |
| 55 |
try { |
| 56 |
thrd.start(); |
| 57 |
|
| 58 |
|
| 59 |
waitForSuspension(thrd); |
| 60 |
|
| 61 |
|
| 62 |
Suspension.resume(thrd); |
| 63 |
waitFor(1000); |
| 64 |
|
| 65 |
|
| 66 |
if (Suspension.isSuspended(thrd)) { |
| 67 |
Suspension.resume(thrd); |
| 68 |
thrd.join(); |
| 69 |
System.out.println("Thread was still suspended after one resume."); |
| 70 |
} else { |
| 71 |
thrd.join(); |
| 72 |
System.out.println("Thread was no longer suspended after one resume."); |
| 73 |
} |
| 74 |
|
| 75 |
} catch (Throwable t) { |
| 76 |
System.out.println("something was thrown. Runtime might be in unrecoverable state: " + t); |
| 77 |
t.printStackTrace(); |
| 78 |
Runtime.getRuntime().halt(2); |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
} |