equal
deleted
inserted
replaced
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @bug 6400879 7100140 |
26 * @bug 6400879 7100140 |
27 * @summary Tests that Start/Stop sequence doesn't hang |
27 * @summary Tests that Start/Stop sequence doesn't hang |
28 * @author Alexey Menkov |
28 * @author Alexey Menkov |
29 * @run main bug6400879 |
29 * @run main/othervm bug6400879 |
30 * @key intermittent |
|
31 */ |
30 */ |
|
31 |
|
32 import java.util.concurrent.TimeUnit; |
32 |
33 |
33 import javax.sound.sampled.*; |
34 import javax.sound.sampled.*; |
34 |
35 |
35 public class bug6400879 extends Thread { |
36 public class bug6400879 extends Thread { |
36 |
37 |
48 public static void monitor(bug6400879 pThis) throws Exception { |
49 public static void monitor(bug6400879 pThis) throws Exception { |
49 long prevLoop = -1; |
50 long prevLoop = -1; |
50 long prevTime = currentTimeMillis(); |
51 long prevTime = currentTimeMillis(); |
51 while (pThis.isAlive()) { |
52 while (pThis.isAlive()) { |
52 if (pThis.loopCounter == prevLoop) { |
53 if (pThis.loopCounter == prevLoop) { |
53 if (currentTimeMillis() - prevTime > BLOCK_TIMEOUT) { |
54 long delay = currentTimeMillis() - prevTime; |
54 // block! |
55 if (delay > BLOCK_TIMEOUT) { |
55 log("Test FAILED."); |
56 // blocked? |
56 throw new RuntimeException("Test FAILED: thread has been blocked!"); |
57 log("The test is slow, delay = " + delay); |
57 } |
58 } |
58 } else { |
59 } else { |
59 prevLoop = pThis.loopCounter; |
60 prevLoop = pThis.loopCounter; |
60 prevTime = currentTimeMillis(); |
61 prevTime = currentTimeMillis(); |
61 } |
62 } |
62 delay(500); // sleep for 0.5 sec |
63 delay(1000); // sleep for 1 sec |
63 } |
64 } |
64 log("Test sucessfully passed."); |
65 log("Test sucessfully passed."); |
65 } |
66 } |
66 |
67 |
67 volatile long loopCounter = 0; |
68 volatile long loopCounter = 0; |
109 |
110 |
110 |
111 |
111 // helper routines |
112 // helper routines |
112 static long startTime = currentTimeMillis(); |
113 static long startTime = currentTimeMillis(); |
113 static long currentTimeMillis() { |
114 static long currentTimeMillis() { |
114 //return System.nanoTime() / 1000000L; |
115 return TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); |
115 return System.currentTimeMillis(); |
|
116 } |
116 } |
117 static void log(String s) { |
117 static void log(String s) { |
118 long time = currentTimeMillis() - startTime; |
118 long time = currentTimeMillis() - startTime; |
119 long ms = time % 1000; |
119 long ms = time % 1000; |
120 time /= 1000; |
120 time /= 1000; |