countworker.java

来自「分布式计算平台P2HP-1的源代码;P2HP-1是基于P2P的高性能计算平台」· Java 代码 · 共 86 行

JAVA
86
字号
/*
 * Created on 2005-3-29
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package cn.edu.hust.cgcl.biogrid.dispatcher;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;

/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class CountWorker {
	private final Timer timer = new Timer(true);
    private final int minutes;
    private Vector workerNodeList;
    
    private int c=0;
    private Integer in;
    private boolean computeFlag=true;
    
    public static int workerCount[];
    //public static int workerCountTemp[];
    private LinkedList ll;

    public CountWorker(int minutes,Vector workerNodeList) {
    	workerCount=new int[60]; 
    	for(int j=0;j<60;j++)
    		workerCount[j]=0;
    	//workerCountTemp=new int[60];
    	ll=new LinkedList();
        this.minutes = minutes;
        this.workerNodeList=workerNodeList;
    }

    public void start() {
        timer.schedule(new TimerTask() {
            public void run() {
                count();
                //timer.cancel();
            }
            private void count() {
                // Start a new thread to count...
            	in=new Integer(workerNodeList.size());
        		ll.add(in);
            	if(computeFlag)
            	 {
            		for(int j=59-c;j<59;j++)
            			workerCount[j]=workerCount[j+1];
            		workerCount[59]=workerNodeList.size();
            		if(++c>=60)
            			computeFlag=false;
            	 }
            	else 
            	{
            		c=0;
            		//workerCount[c++]=workerNodeList.size();
            		ListIterator iter=ll.listIterator();
            		iter.next();
            		iter.remove();
            		while(iter.hasNext())
            		{
            			workerCount[c++]=((Integer)(iter.next())).intValue();
            		}
            		
            	}
            }
        },  minutes *1000, minutes *60 *1000);
    }
    
    public void quit()
    {
    	timer.cancel();
    }
    


}

⌨️ 快捷键说明

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