Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/CriticalSectionTimedLocker.java
41162 views
/*1* Copyright (c) 2007, 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.lock;2425import nsk.share.TestBug;26import nsk.share.gc.lock.Locker;2728/**29* CriticalSectionTimedLocker represents a way to lock a resource30* by entering some critical section for some time.31*/32public abstract class CriticalSectionTimedLocker<T> extends CriticalSectionLocker<T> {33private long enterTime;34private long sleepTime;3536public CriticalSectionTimedLocker() {37this(5000, 10);38}3940public CriticalSectionTimedLocker(long enterTime, long sleepTime) {41setEnterTime(enterTime);42setSleepTime(sleepTime);43}4445protected final void criticalSection() {46criticalSection(enterTime, sleepTime);47}4849/**50* Enter critical section for enterTime.51*52* Usually, something is done in a loop inside this critical section.53* In this case, sleepTime is time to sleep after each iteration.54*/55protected abstract void criticalSection(long enterTime, long sleepTime);5657public final void setEnterTime(long enterTime) {58this.enterTime = enterTime;59}6061public final void setSleepTime(long sleepTime) {62this.sleepTime = sleepTime;63}64}656667