• 大小: 86KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-01-10
  • 语言: 其他
  • 标签: 多线程  

资源简介

此例子,在web项目一启动之后,配制的线程能定时的执行...............

资源截图

代码片段和文件信息

package com.jiexun;

import java.util.Calendar;
import java.util.TimerTask;

import javax.servlet.ServletContext;

/**
 * @creator  xiaoyoubiao
 * @create-time 2010-3-23下午04:14:54
 * @Copyright www.19pay.com.cn
 **/
public class MyTask extends TimerTask {
private static boolean isRunning = false;

private static boolean flag = true;

private static final int C_SCHEDULE_HOUR = 23;

private ServletContext context = null;

public MyTask(ServletContext context) {

this.context = context;

}

public void run() {

context.log(“开始执行指定任务“);
//  添加自定义的详细任务    
try {
Calendar cal = Calendar.getInstance();
if (!isRunning) {
System.out.println(“-----------执行MyTask的任务---------------“);
if (C_SCHEDULE_HOUR == cal.get(Calendar.HOUR_OF_DAY) &

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     目录          0  2010-03-23 16:34  ThreadDemo

     文件        332  2010-03-23 16:34  ThreadDemo\.classpath

     文件        386  2010-03-22 17:51  ThreadDemo\.project

     目录          0  2010-03-23 16:34  ThreadDemo\src

     目录          0  2010-03-23 16:34  ThreadDemo\src\com

     目录          0  2010-03-23 16:34  ThreadDemo\src\com\jiexun

     文件       1233  2010-03-23 16:33  ThreadDemo\src\com\jiexun\MyTask.java

     文件        329  2010-03-23 16:32  ThreadDemo\src\com\jiexun\MyTask2.java

     文件        674  2010-03-23 16:31  ThreadDemo\src\com\jiexun\Task.java

     文件        842  2010-03-23 16:24  ThreadDemo\src\com\jiexun\TimerListener.java

     目录          0  2010-03-23 16:34  ThreadDemo\ThreadDemo

     目录          0  2010-03-23 16:34  ThreadDemo\ThreadDemo\WEB-INF

     目录          0  2010-03-23 16:34  ThreadDemo\ThreadDemo\WEB-INF\classes

     目录          0  2010-03-23 16:34  ThreadDemo\ThreadDemo\WEB-INF\classes\com

     目录          0  2010-03-23 16:34  ThreadDemo\ThreadDemo\WEB-INF\classes\com\jiexun

     文件       1322  2010-03-23 16:34  ThreadDemo\ThreadDemo\WEB-INF\classes\com\jiexun\MyTask.class

     文件        529  2010-03-23 16:34  ThreadDemo\ThreadDemo\WEB-INF\classes\com\jiexun\MyTask2.class

     文件        865  2010-03-23 16:34  ThreadDemo\ThreadDemo\WEB-INF\classes\com\jiexun\Task.class

     文件       1227  2010-03-23 16:34  ThreadDemo\ThreadDemo\WEB-INF\classes\com\jiexun\TimerListener.class

     目录          0  2010-03-23 16:34  ThreadDemo\ThreadDemo\WEB-INF\lib

     文件      88199  2010-03-22 17:47  ThreadDemo\ThreadDemo\WEB-INF\lib\servlet-api.jar

     文件        379  2010-03-23 16:20  ThreadDemo\ThreadDemo\WEB-INF\web.xml

----------- ---------  ---------- -----  ----

                96317                    22


评论

共有 条评论