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

📄 closeablethread.java

📁 FMJ(freedom media for java)是java视频开发的新选择
💻 JAVA
字号:
package com.lti.utils.synchronization;/** * A base class for threads which need to be gracefully closed, since Thread.stop() is * deprecated.  Subclass should check isClosing() in their main loop in run(), and  * call setClosed() when run() completes. *  * @author Ken Larson */public abstract class CloseableThread extends Thread{	protected final SynchronizedBoolean closing = new SynchronizedBoolean(false); 	private final SynchronizedBoolean closed = new SynchronizedBoolean(false); 		/** @deprecated */	public CloseableThread()	{		super();	}	/** @deprecated */	public CloseableThread(String threadName)	{		super(threadName);	}	public CloseableThread(final ThreadGroup group, final String threadName)	{		super(group, threadName);	}	public void close()		{	closing.setValue(true);		interrupt();	}	protected void setClosing()	{		closing.setValue(true);	}	public boolean isClosed()	{	return closed.getValue();	}	public void waitUntilClosed() throws InterruptedException	{	closed.waitUntil(true);	}		/**	 * intended to be checked by thread in its main loop.  break out of the main loop	 * if true.	 */	protected boolean isClosing()	{	return closing.getValue();	}		/**	 * to be called by the thread upon exit.	 */	protected void setClosed()	{	closed.setValue(true);	}}

⌨️ 快捷键说明

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