semaphore.java

来自「j2me 上面flash播放器。非常值得研究。就是版本只到2.0」· Java 代码 · 共 58 行

JAVA
58
字号
package org.jflashme;/*  This library is free software; you can redistribute it and/or modify it *  under the terms of the GNU Lesser General Public License, version 2, as *  published by the Free Software Foundation. * *  This library 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 *  Lesser General Public License (the accompanying file named LGPL.txt) *  for more details. */final class Semaphore{   private boolean state;    Semaphore(boolean flag)    {        state = flag;    }    synchronized boolean isSet()    {        return state;    }    synchronized void waitForTrue()        throws InterruptedException    {        while(!state)             wait();    }    synchronized void waitForEvent()        throws InterruptedException    {        while(!state)             wait();        state = false;    }    synchronized void set()    {        if(!state)            state = true;        notifyAll();    }    synchronized boolean clear()    {        boolean flag = state;        state = false;        return flag;    }}

⌨️ 快捷键说明

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