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

📄 timerschedule.java

📁 采用JAVA开发
💻 JAVA
字号:
/*
 * Created on 2004-8-6
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package com.gctech.misc.other.time;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimerTask;

/**
 * <p>Title:</p>
 * <p>Description:</p>
 * <p>Copyright: Copyright (c) Gctech 2004-8-6</p>
 * <p>Company: 吉芙德资讯有限公司</p>
 *
 * @version 1.0
 * @author liyi
 *
 */
   public class  TimerSchedule extends TimerTask
  {
	private List list  = new ArrayList();
	public TimerSchedule()
	{
    
	}
	public void addTimerJob(TimerJob job)
	{
	  list.add(job);
	}

	public void run()
	{
	  Date now  = Calendar.getInstance().getTime();
	  Date next = null;
	  for(int i=0;i<list.size();i++)
	  {

		TimerJob job = (TimerJob)list.get(i);
		next = job.getNextExeDate();
		if(isEquals(now,next))
		{
		  job.execute();
		}
	  }
	}

	/**
	 * 比较俩个时间相差是否小于TimerService.p(一个周期)
	 * @param now
	 * @param next
	 * @return
	 */
	private boolean isEquals(Date now,Date next)
	{
	  long time = next.getTime()-now.getTime();


	  if (time <= TimerService.p && time >= 0)
	  {
		return true;
	  }
	  else
	  {
		return false;
	  }
	}

	public boolean cancel()
	{
	  return true;
	}
   }

⌨️ 快捷键说明

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