⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readwritelock.java

📁 Jive是基于JSP/JAVA技术构架的一个大型BBS论坛系统,这是Jive论坛2.6版本的源程序
💻 JAVA
字号:
/** * $RCSfile: ReadWriteLock.java,v $ * $Revision: 1.1 $ * $Date: 2002/07/07 16:29:08 $ * * Copyright (C) 2002 CoolServlets, Inc. All rights reserved. * * This software is the proprietary information of CoolServlets, Inc. * Use is subject to license terms. */package com.jivesoftware.util;/** * Simple read write lock class that allows multiple readers but only 1 writer. Waiting writers are * treated preferentially to waiting readers. */public class ReadWriteLock {    private int readers = 0;    private boolean writingInProgress = false;    private boolean waitingWriter = false;    public ReadWriteLock() { }    public synchronized void acquireReadLock() {        while (writingInProgress || waitingWriter == true) {            try {                wait();            }            catch (InterruptedException ie) { /* ignore */ }        }        readers++;    }    public synchronized void releaseReadLock() {        readers--;        if (readers == 0) {            notify();        }    }    public synchronized void acquireWriteLock() {        while (readers > 0 || writingInProgress) {            try {                waitingWriter = true;                wait();            }            catch (InterruptedException ie) { /* ignore */ }        }        writingInProgress = true;        waitingWriter = false;    }    public synchronized void releaseWriteLock() {        writingInProgress = false;        notifyAll();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -