19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 6450200
27 * @summary Test proper handling of pool state changes
28 * @run main/othervm ConfigChanges
29 * @author Martin Buchholz
30 */
31
32 import java.security.*;
33 import java.util.*;
34 import java.util.concurrent.*;
35 import java.util.concurrent.atomic.*;
36 import static java.util.concurrent.TimeUnit.*;
37
38 public class ConfigChanges {
39 final static ThreadGroup tg = new ThreadGroup("pool");
40
41 final static Random rnd = new Random();
42
43 static void report(ThreadPoolExecutor tpe) {
44 try {
45 System.out.printf(
46 "active=%d submitted=%d completed=%d queued=%d sizes=%d/%d/%d%n",
47 tg.activeCount(),
48 tpe.getTaskCount(),
49 tpe.getCompletedTaskCount(),
50 tpe.getQueue().size(),
51 tpe.getPoolSize(),
52 tpe.getCorePoolSize(),
53 tpe.getMaximumPoolSize());
54 } catch (Throwable t) { unexpected(t); }
55 }
56
57 static void report(String label, ThreadPoolExecutor tpe) {
58 System.out.printf("%10s ", label);
59 report(tpe);
60 }
61
224 tpe.shutdown();
225 checkShutdown(tpe);
226 check(tpe.awaitTermination(3L, MINUTES));
227 checkTerminated(tpe);
228 }
229
230 //--------------------- Infrastructure ---------------------------
231 static volatile int passed = 0, failed = 0;
232 static void pass() {passed++;}
233 static void fail() {failed++; Thread.dumpStack();}
234 static void fail(String msg) {System.out.println(msg); fail();}
235 static void unexpected(Throwable t) {failed++; t.printStackTrace();}
236 static void check(boolean cond) {if (cond) pass(); else fail();}
237 static void equal(Object x, Object y) {
238 if (x == null ? y == null : x.equals(y)) pass();
239 else fail(x + " not equal to " + y);}
240 public static void main(String[] args) throws Throwable {
241 try {realMain(args);} catch (Throwable t) {unexpected(t);}
242 System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
243 if (failed > 0) throw new AssertionError("Some tests failed");}
244 private static abstract class Fun {abstract void f() throws Throwable;}
245 static void THROWS(Class<? extends Throwable> k, Fun... fs) {
246 for (Fun f : fs)
247 try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
248 catch (Throwable t) {
249 if (k.isAssignableFrom(t.getClass())) pass();
250 else unexpected(t);}}
251 }
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 6450200
27 * @summary Test proper handling of pool state changes
28 * @run main/othervm ConfigChanges
29 * @author Martin Buchholz
30 */
31
32 import java.security.*;
33 import java.util.*;
34 import java.util.concurrent.*;
35 import java.util.concurrent.atomic.*;
36 import static java.util.concurrent.TimeUnit.*;
37
38 public class ConfigChanges {
39 static final ThreadGroup tg = new ThreadGroup("pool");
40
41 static final Random rnd = new Random();
42
43 static void report(ThreadPoolExecutor tpe) {
44 try {
45 System.out.printf(
46 "active=%d submitted=%d completed=%d queued=%d sizes=%d/%d/%d%n",
47 tg.activeCount(),
48 tpe.getTaskCount(),
49 tpe.getCompletedTaskCount(),
50 tpe.getQueue().size(),
51 tpe.getPoolSize(),
52 tpe.getCorePoolSize(),
53 tpe.getMaximumPoolSize());
54 } catch (Throwable t) { unexpected(t); }
55 }
56
57 static void report(String label, ThreadPoolExecutor tpe) {
58 System.out.printf("%10s ", label);
59 report(tpe);
60 }
61
224 tpe.shutdown();
225 checkShutdown(tpe);
226 check(tpe.awaitTermination(3L, MINUTES));
227 checkTerminated(tpe);
228 }
229
230 //--------------------- Infrastructure ---------------------------
231 static volatile int passed = 0, failed = 0;
232 static void pass() {passed++;}
233 static void fail() {failed++; Thread.dumpStack();}
234 static void fail(String msg) {System.out.println(msg); fail();}
235 static void unexpected(Throwable t) {failed++; t.printStackTrace();}
236 static void check(boolean cond) {if (cond) pass(); else fail();}
237 static void equal(Object x, Object y) {
238 if (x == null ? y == null : x.equals(y)) pass();
239 else fail(x + " not equal to " + y);}
240 public static void main(String[] args) throws Throwable {
241 try {realMain(args);} catch (Throwable t) {unexpected(t);}
242 System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
243 if (failed > 0) throw new AssertionError("Some tests failed");}
244 private abstract static class Fun {abstract void f() throws Throwable;}
245 static void THROWS(Class<? extends Throwable> k, Fun... fs) {
246 for (Fun f : fs)
247 try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
248 catch (Throwable t) {
249 if (k.isAssignableFrom(t.getClass())) pass();
250 else unexpected(t);}}
251 }
|