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

📄 mcommandexecuter.java

📁 httptunnel.jar httptunnel java 源码
💻 JAVA
字号:
package net.jumperz.util;

import java.io.*;
import net.jumperz.util.*;
import java.util.*;

public final class MCommandExecuter
extends MSingleThreadCommand
{
private LinkedList commandQueue = new LinkedList();
private int maxQueueCount = MAX_QUEUE_COUNT; // 0 means infinite
private long interval = DEFAULT_INTERVAL;
private boolean sleeping = false;

private static final MCommandExecuter instance = new MCommandExecuter();
private static final long DEFAULT_INTERVAL = 1000; // 1 second
private static final int MAX_QUEUE_COUNT = 50;
//--------------------------------------------------------------------------------
public static MCommandExecuter getInstance()
{
return instance;
}
//--------------------------------------------------------------------------------
public void setInterval( long l )
{
interval = l;
}
//--------------------------------------------------------------------------------
public void setMaxQueueCount( int i )
{
maxQueueCount = i;
}
//--------------------------------------------------------------------------------
public void addCommand( String command )
{
synchronized( commandQueue )
	{
	commandQueue.addLast( command );
	}

synchronized( mutex )
	{
	mutex.notify();
	}
}
//--------------------------------------------------------------------------------
protected void execute2()
{
while( !commandQueue.isEmpty() )
	{
	String command = null;
	synchronized( commandQueue )
		{
		if( maxQueueCount > 0
		 && commandQueue.size() >=  maxQueueCount
		  )
			{
			Iterator p = commandQueue.iterator();
			while( p.hasNext() )
				{
				String commandInQueue = ( String )p.next();
				//MLogger.getInstance().Log( "Too many commands in queue : " + commandInQueue );
				}
			commandQueue.clear();
			}
		else
			{
			command = ( String )commandQueue.getFirst();
			commandQueue.removeFirst();
			try
				{
				Runtime.getRuntime().exec( command );
				}
			catch( IOException e )
				{
				e.printStackTrace();
				}
			}
		}
	
	try
		{
		sleeping = true;
		Thread.sleep( interval );
		sleeping = false;
		}
	catch( InterruptedException e )
		{
		e.printStackTrace();
		break;
		}
	}
}
//--------------------------------------------------------------------------------
private MCommandExecuter()
{
mutex = this;
}
//--------------------------------------------------------------------------------
public void breakCommand()
{
terminated = true;
if( sleeping )
	{
	myThread.interrupt();
	}
else
	{
	synchronized( this )
		{
		notify();
		}
	}
}
//--------------------------------------------------------------------------------
}

⌨️ 快捷键说明

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