Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/gc/ThreadedGCTest.java
41161 views
/*1* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package nsk.share.gc;2425import nsk.share.runner.*;26import nsk.share.test.ExecutionController;27import nsk.share.Consts;2829/**30* Test that executes a number of tasks.31*32* How these tasks are used is determined by MultiRunner.33* Usually they are executed in separate threads in cycle34* for some time or for some iterations.35*36* @see nsk.share.runner.MultiRunner37* @see nsk.share.runner.ThreadsRunner38*/39public abstract class ThreadedGCTest extends GCTestBase implements MultiRunnerAware {40private MultiRunner runner;4142/**43* Create a task with index i.44*45* Subclasses should to override this method46* to created neccessary tasks.47*48* @param i index of task49* @return task to run or null50*/51protected abstract Runnable createRunnable(int i);5253protected ExecutionController getExecutionController() {54return runner.getExecutionController();55}5657protected final boolean runThreads() {58for (int i = 0; i < runParams.getNumberOfThreads(); ++i) {59Runnable runnable = createRunnable(i);60if (runnable != null)61runner.add(runnable);62}63runner.run();64return runner.isSuccessful();65}6667public void run() {68if (!runThreads())69setFailed(true);70}7172public final void setRunner(MultiRunner runner) {73this.runner = runner;74}75}767778