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

📄 loop.java

📁 是一个用java实现的
💻 JAVA
字号:
/*
 * Loop.java
 * 
 * Created on Mar 16, 2004
 *
 */
package gov.nist.applet.phone.media.messaging;

import javax.media.protocol.PullBufferStream;

/**
 *  This is a processing loop to get data from a BufferDataSourceHandler.
 * 
 * @author Jean Deruelle <jean.deruelle@nist.gov>
 *
 * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
 */
public class Loop extends Thread {

	RawDataSourceHandler handler;
	PullBufferStream stream;
	boolean paused = true;
	boolean killed = false;

	/**
	 * Constructs a processing loop to get data from a BufferDataSourceHandler.
	 * @param handler - the data source handler where to handle the data
	 * @param stream - the stream from where to get the data
	 */
	public Loop(RawDataSourceHandler handler, PullBufferStream stream) {
	    this.handler = handler;
	    this.stream = stream;
	    start();
	}

	/**
	 * Continue the process
	 */
	public synchronized void restart() {
	    paused = false;
	    notify();
	}

	/**
	 * This is the correct way to pause a thread; unlike suspend.
	 */
	public synchronized void pause() {
	    paused = true;
	}

	/**
	 * This is the correct way to kill a thread; unlike stop.
	 */
	public synchronized void kill() {
	    killed = true;
	    notify();
	}

	/**
	 * This is the processing loop to pull data from a 
	 * BufferDataSourceHandler.
	 */
	public void run() {
	    while (!killed) {
		try {
		    while (paused && !killed) {
			wait();
		    }
		} catch (InterruptedException e) {}

		if (!killed) {
		    boolean done = handler.readPullData(stream);
		    if (done)
			pause();
		}
	    }
	}

}

⌨️ 快捷键说明

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