Purge.java revision 2362
2736N/A/*
2736N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
2736N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2736N/A *
2736N/A * This code is free software; you can redistribute it and/or modify it
2736N/A * under the terms of the GNU General Public License version 2 only, as
2736N/A * published by the Free Software Foundation.
2736N/A *
2736N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2736N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2736N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2736N/A * version 2 for more details (a copy is included in the LICENSE file that
2736N/A * accompanied this code).
2736N/A *
2736N/A * You should have received a copy of the GNU General Public License version
2736N/A * 2 along with this work; if not, write to the Free Software Foundation,
2736N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2736N/A *
2736N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2736N/A * or visit www.oracle.com if you need additional information or have any
2736N/A * questions.
2736N/A */
2736N/A
2736N/A/*
2736N/A * @test
2736N/A * @bug 4481072
2736N/A * @summary Basic test for purge method
2736N/A */
2736N/A
2736N/Aimport java.util.*;
2736N/A
2736N/Apublic class Purge {
2736N/A public static void main (String[] args) {
2736N/A Random rnd = new Random();
2736N/A Timer timer = new Timer();
2736N/A int cancelled = 0;
2736N/A for (long i = 1; i <= 1000; i++) {
2736N/A TimerTask task = new TimerTask() {
2736N/A public void run() {
2736N/A System.out.println("How come no one ever calls me?");
2736N/A }
2736N/A };
2736N/A timer.schedule(task, i * 60*60*1000); // i hrs. hence.
2736N/A if (i != 1 && rnd.nextBoolean()) {
2736N/A task.cancel();
2736N/A cancelled++;
2736N/A }
2736N/A }
2736N/A int purged = timer.purge();
2736N/A if (purged != cancelled)
2736N/A throw new RuntimeException(purged + " != " + cancelled);
2736N/A purged = timer.purge();
2736N/A if (purged != 0)
2736N/A throw new RuntimeException(purged + " nonzero");
2736N/A timer.cancel();
2736N/A }
2736N/A}
2736N/A