37N/A/*
2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
37N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
37N/A *
37N/A * This code is free software; you can redistribute it and/or modify it
37N/A * under the terms of the GNU General Public License version 2 only, as
37N/A * published by the Free Software Foundation.
37N/A *
37N/A * This code is distributed in the hope that it will be useful, but WITHOUT
37N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
37N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
37N/A * version 2 for more details (a copy is included in the LICENSE file that
37N/A * accompanied this code).
37N/A *
37N/A * You should have received a copy of the GNU General Public License version
37N/A * 2 along with this work; if not, write to the Free Software Foundation,
37N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
37N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
37N/A */
37N/A
37N/Aimport java.util.concurrent.*;
37N/Aimport static java.util.concurrent.TimeUnit.*;
37N/A
37N/A/**
37N/A * This is not a regression test, but a stress benchmark test for
37N/A * 6609775: Reduce context switches in DelayQueue due to signalAll
37N/A *
37N/A * This runs in the same wall clock time, but much reduced cpu time,
37N/A * with the changes for 6609775.
37N/A */
37N/Apublic class Stress {
37N/A
37N/A public static void main(String[] args) throws Throwable {
37N/A
37N/A final DelayQueue<Delayed> q = new DelayQueue<Delayed>();
37N/A final long t0 = System.nanoTime();
37N/A for (long i = 0; i < 1000; i++) {
37N/A final long expiry = t0 + i*10L*1000L*1000L;
37N/A q.add(new Delayed() {
37N/A public long getDelay(TimeUnit unit) {
37N/A return unit.convert(expiry - System.nanoTime(),
37N/A NANOSECONDS);
37N/A }
37N/A public int compareTo(Delayed x) {
37N/A long d = getDelay(NANOSECONDS)
37N/A - x.getDelay(NANOSECONDS);
37N/A return d < 0 ? -1 : d > 0 ? 1 : 0; }});
37N/A }
37N/A
37N/A for (int i = 0; i < 300; i++)
37N/A new Thread() { public void run() {
37N/A try {
37N/A while (!q.isEmpty())
37N/A q.poll(10L, TimeUnit.SECONDS);
37N/A } catch (Throwable t) { t.printStackTrace(); }
37N/A }}.start();
37N/A }
37N/A}