mworkerthread.java

来自「httptunnel.jar httptunnel java 源码」· Java 代码 · 共 87 行

JAVA
87
字号
package net.jumperz.util;

public final class MWorkerThread
extends Thread
{
private MCommand command;
private boolean suspended;
private volatile boolean terminated;
private MThreadPool threadPool;
//--------------------------------------------------------------------
public MWorkerThread( MThreadPool in_threadPool )
{
threadPool	= in_threadPool;
terminated	= false;
suspended	= true;
start();
}
//--------------------------------------------------------------------
public final void run()
{
while( !terminated )
	{
	synchronized( this )
		{
		while( suspended )
			{
			try
				{
				wait();
				}
			catch( Exception e )
				{
				e.printStackTrace();
				//break;
				}
			}
		}
	
	if( terminated )
		{
		break;
		}

	try
		{
		command.execute();
		}
	catch( Throwable e )
		{
		 // execute() throws no Exception
		System.err.println( "########## Caught a Throwable #########" );
		e.printStackTrace();
		command.breakCommand();	
		}

	command = null;
	suspended = true;
	threadPool.setThreadWait( this );
	}
}
//--------------------------------------------------------------------
public final void setCommand( MCommand in_Command )
{
command = in_Command;
}
//--------------------------------------------------------------------
public final void terminate()
{
terminated = true;
}
//--------------------------------------------------------------------
public final synchronized void resumeThread()
{
suspended = false;
notify();
}
//--------------------------------------------------------------------
public final void breakThread()
{
if( command != null )
	{
	command.breakCommand();
	}
}
//--------------------------------------------------------------------
}

⌨️ 快捷键说明

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