?? threadmanager.java
字號:
package com.hoten.util;
import java.util.*;
/**
* <p>Title: 線程管理類</p>
* <p>Description:主要用來管理程序中的線程,
* 在動態加載與卸載中將有此類來完成在程序中增加與刪除線程
* 此類基本有兩種方法,get和set主要是對里面的屬性進行操作。
* </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: 江蘇宏圖嘉騰軟件系統有限公司</p>
* @author hoten
* @version 1.0
*/
public class ThreadManager {
static private ThreadManager _instance;
private Hashtable _threadList;
private ThreadGroup _tgRoot;
private ThreadGroup _tgControl;
private ThreadGroup _tgDeal;
private ThreadGroup _tgRead;
private ThreadGroup _tgSendMT;
/**
* 使用此方法獲得本類唯一實例。
* @return
*/
static synchronized public ThreadManager getInstance() {
if (_instance == null) {
_instance = new ThreadManager();
}
return _instance;
}
private ThreadManager() {
_tgRoot =new ThreadGroup("Root");
_tgControl =new ThreadGroup(_tgRoot,"Control");
_tgDeal =new ThreadGroup(_tgRoot,"Deal");
_tgRead =new ThreadGroup(_tgRoot,"Read");
_tgSendMT =new ThreadGroup(_tgRoot,"Send");
_threadList =new Hashtable();
}
public synchronized ThreadGroup getRootGroup(){
return _tgRoot;
}
public synchronized void stopRootGroup(){
_tgRoot.interrupt();
}
public synchronized ThreadGroup getControlGroup(){
return _tgControl;
}
public synchronized void stopControlGroup() {
_tgControl.interrupt();
}
public ThreadGroup getDealGroup(){
return _tgDeal;
}
public synchronized void stopDealGroup() {
_tgDeal.interrupt();
}
public synchronized ThreadGroup getReadGroup(){
return _tgRead;
}
public synchronized void stopReadGroup() {
_tgRead.interrupt();
}
public synchronized ThreadGroup getSendMTGroup(){
return _tgSendMT;
}
public synchronized void stopSendMTGroup() {
_tgSendMT.interrupt();
}
/**
* 向線程隊列中添加一線程
* @param threadName 線程的名稱
* @param thread 線程實例
*/
public synchronized void addThread(String threadName,Thread thread){
_threadList.put(threadName,thread);
}
/**
* 得到一個線程實例
* @param threadName 要取得的線程名
* @return Thread 線程實例
*/
public synchronized Thread getThread(String threadName){
return (Thread)_threadList.get(threadName);
}
/**
* 得到一個線程實例,同時把該實例從線程隊列中刪除
* @param threadName 要刪除的線程名
* @return Thread 線程實例
*/
public synchronized Thread removeThread(String threadName){
return (Thread)_threadList.remove(threadName);
}
/**
* 取得線程隊列
* @return Hashtable 隊列實例
*/
public synchronized Hashtable getThreadList(){
return _threadList;
}
/**
* 清空線程隊列
*/
public synchronized void removeAllThread(){
_threadList.clear();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -