www.pudn.com > TestToolsProject.rar > ThreadSource.java, change:2014-03-26,size:1811b


package com.mervyn.testsource; 
 
import java.text.DateFormat; 
import java.text.ParseException; 
import java.text.SimpleDateFormat; 
import java.util.Date; 
import java.util.Timer; 
import java.util.TimerTask; 
 
public class ThreadSource { 
	public static TimerTask runTimes(String args,final char ExcuteStr) {       
        TimerTask task = new TimerTask() {    
            public void run() {    
               switch (ExcuteStr) { 
				case 'a': 
				case 'b': 
				default: 
 
				} 
            	    
            	    
                
            }    
        };    
        return task;    
    }    
    /**   
     * 从某个时间发起定时器   
     * @param time   
     * @param args   
     * @param timeFormat 时间格式   
     * @param date  时间   
     * @return   
     * @throws ParseException   
     */   
    public static Timer startTime(int time,String args,String timeFormat,String date,char ExcuteStr) throws ParseException {    
        Timer timer = new Timer();    
        DateFormat dateFormat2 = new SimpleDateFormat(timeFormat);    
        timer.schedule(runTimes(args,ExcuteStr), dateFormat2.parse(date), time);// 每隔一秒输出    
        return timer;    
    }    
    /**   
     * 从当前时间立刻发起定时器   
     * @param time 时间间隔   
     * @param args 需要输出的字符串   
     * @return   
     * @throws ParseException   
     */   
    public static Timer startTime(int time, String args,char ExcuteStr) throws ParseException {    
        Timer timer = new Timer();    
        timer.schedule(runTimes(args,ExcuteStr), new Date(), time);// 每隔一秒输出    
        return timer;    
    }    
    /**   
     * 停止定时器   
     * @param timer   
     */   
    public static void stopTime(Timer timer,String timerstr) {    
        timer.cancel();  
    } 
}