Context.java revision 2362
* Copyright (c) 2004, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * Sample target application for jvmti demos * java Context [threadCount [iterationCount [sleepContention]]] * Default: java Context 5 10 0 * threadCount Number of threads * iterationCount Total turns taken for all threads * sleepContention Time for main thread to sleep while holding lock * (creates monitor contention on all other threads) /* Used to sync up turns and keep track of who's turn it is */ /* Creates a bunch of threads that sequentially take turns */ /* Used to track threads */ /* Used for each Context thread */ /* Get all threads running (they will block until we set turn) */ /* Sleep to make sure thread_index 0 make it to the wait call */ /* This triggers the starting of taking turns */ /* Wait for threads to finish (after everyone has had their turns) */ /* Create some monitor contention by sleeping with lock */ /* Thread object to run */ /* Loop until we make sure we get all our turns */ /* Keep waiting for our turn */ /* MY TURN! Each thread gets thread_turns */ +
" turns taken by this thread");
/* Give next thread a turn */ /* If we've had all our turns, break out of this loop */ /* Make sure we got all our turns */