--- old/test/java/util/Timer/Args.java 2014-05-30 15:16:36.584810774 +0800 +++ new/test/java/util/Timer/Args.java 2014-05-30 15:16:35.802798098 +0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,8 +23,9 @@ /* * @test - * @bug 6571655 6571881 6574585 6571297 + * @bug 6571655 6571881 6574585 6571297 8004807 * @summary Test various args to task scheduling methods + * @run main/othervm Args */ import java.util.*; @@ -49,11 +50,17 @@ new F(){void f(){ t.scheduleAtFixedRate(task, d, period); }}); } - TimerTask counter(final CountDownLatch latch) { - return new TimerTask() { public void run() { - check(latch.getCount() > 0); - latch.countDown(); - }}; + TimerTask counter(final CountDownLatch latch, final Timer timer, final boolean repeatable) { + return new TimerTask() { + private boolean executed = false; + public void run() { + // check if the unrepeatable task is executed repeatedly. + check(!executed ? executed = true : repeatable); + latch.countDown(); + if (latch.getCount() == 0) { + timer.cancel(); + } + }}; } void test(String[] args) throws Throwable { @@ -92,24 +99,20 @@ new F(){void f(){ t.scheduleAtFixedRate(x, (Date)null, 42); }} ); - final CountDownLatch y1 = new CountDownLatch(1); - final CountDownLatch y2 = new CountDownLatch(1); - final CountDownLatch y3 = new CountDownLatch(11); + final CountDownLatch y = new CountDownLatch(13); final long start = System.currentTimeMillis(); final Date past = new Date(start - 10500); - schedule( t, counter(y1), past); - schedule( t, counter(y2), past, 1000); - scheduleAtFixedRate(t, counter(y3), past, 1000); - y3.await(); - y1.await(); - y2.await(); + schedule(t, counter(y, t, false), past); + schedule(t, counter(y, t, false), past, 1000); + scheduleAtFixedRate(t, counter(y, t, true), past, 1000); + y.await(); final long elapsed = System.currentTimeMillis() - start; - System.out.printf("elapsed=%d%n", elapsed); check(elapsed < 500); + System.out.printf("elapsed=%d%n", elapsed); - t.cancel(); + t.cancel(); //cancel the timer if it hasn't been cancelled by task THROWS(IllegalStateException.class, new F(){void f(){ t.schedule(x, 42); }},