log4j 在代码中的应用



import java.util.Vector;
import java.util.concurrent.LinkedBlockingQueue;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.nufront.euht.web.charts.data.cpu.business.EbuPerformanceThread;
import com.nufront.euht.web.common.util.MyTimeUtil;

public class SnmpThreadPool {
	
	private int threadNumber;
	
	private Vector<Thread> runningVector = new Vector<Thread>();
	
	private LinkedBlockingQueue<Thread> waitingQueue = new LinkedBlockingQueue<Thread>();
	
	private final int SLEEP = 100;
	
	private int number = 0;
	
	private  Log log = LogFactory.getLog(SnmpThreadPool.class);
	
	public SnmpThreadPool(int threadNumber){
		log.debug("运行EbuSnmpThreadPool构造方法");
		this.threadNumber = threadNumber;
		Thread thread = new Thread(new ThreadCheck());
		thread.setName("ThreadCheck Thread");
		thread.start();
	}
    public synchronized void execute(Thread thread){
    	waitingQueue.add(thread);
    }  
    
     class ThreadCheck implements Runnable{
        private  Log threadCheckLog = LogFactory.getLog(ThreadCheck.class);
        @Override
		public void run() {
        	threadCheckLog.debug("运行ThreadCheck run方法");
			while(true){
				try {
					Thread.sleep(SLEEP);
					if(runningVector.size() > 0){
						for(int i = 0 ; i < runningVector.size()  ; i++){
							Thread  current =  runningVector.get(i);
							if(!current.isAlive()){
								runningVector.remove(i);
							}
						}
					}
				    number = threadNumber - runningVector.size();
					if(number>0){
						for(int i = 0 ; i < number ;i++){
							if(waitingQueue.size()>0){
								Thread newThread =  waitingQueue.poll();
								runningVector.add(newThread);
								newThread.start();
//								Thread.sleep(500);
							}  
						}
					}
					//测试代码
					if(waitingQueue.size()==0){
						log.debug("结束时间为 : "+ MyTimeUtil.getNowTime());
					}

				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
			
		}
        
        
    	
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值