command.java
来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 62 行
JAVA
62 行
/*
* $Id: Command.java,v 1.1 2003/11/25 11:41:47 epr Exp $
*/
package org.jnode.util;
/**
* @author epr
*/
public abstract class Command {
/** Is this command finished yet? */
private boolean finished = false;
/**
* Has this command finished?
* @return boolean
*/
public boolean isFinished() {
return finished;
}
/**
* Mark this command as finished.
* Notify all waiting threads.
*/
protected synchronized void notifyFinished() {
finished = true;
notifyAll();
}
/**
* Block the current thread, until this command has finished.
* @throws InterruptedException
*/
public synchronized void waitUntilFinished()
throws InterruptedException {
while (!finished) {
wait();
}
}
/**
* Block the current thread, until this command has finished.
* @param timeout
* @throws InterruptedException This thread was interrupted
* @throws TimeoutException A timeout occurred.
*/
public synchronized void waitUntilFinished(long timeout)
throws InterruptedException, TimeoutException {
final long start = System.currentTimeMillis();
while (!finished) {
wait(timeout);
if ((timeout > 0) && (!finished)) {
if (System.currentTimeMillis() >= start+timeout) {
throw new TimeoutException("timeout");
}
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?