帮助顶一下,顺便学习一下~

解决方案 »

  1.   

    欢迎欢迎服务器启动的时候装载一个线程。
      

  2.   

    吃过回来给帮你看看:)偶去吃饭
      

  3.   

    给你找一段代码:)import java.util.Date;
    import javax.management.Notification;
    import javax.management.NotificationListener;
    import javax.management.InstanceNotFoundException;
    import javax.servlet.ServletContextEvent;
    import javax.servlet.ServletContextListener;
    import weblogic.management.timer.Timer;/**
     * 该类实现了NotificationListener(通知监听)接口
     */public final class PlanTask
        implements
        ServletContextListener, NotificationListener {//  private static final long PERIOD = Timer.ONE_HOUR; //小时
      private static final long PERIOD = Timer.ONE_DAY;
      private Timer timer;
      private int count = 0;  private Integer notificationId;  public void contextInitialized(ServletContextEvent event) {
        System.out.println(">>>正在载入.......");    // Instantiating the Timer MBean
        timer = new Timer();
    //==============================================================    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
            "M/dd/yyyy hh:mm:ss a", java.util.Locale.US);
        java.util.Date d = null;
        try {
          d = sdf.parse("08/02/2004 13:30:00 AM");
        }
        catch (Exception e) {    }//===================================================================
        timer.addNotificationListener(this, null, "some handback Object");    // Adding the notification to the Timer and assigning the
        // ID that the Timer returns to a variable
        Date timerTriggerAt = new Date( (new Date()).getTime() + 5000L);
        notificationId = timer.addNotification("启动任务/分", "a recurring call",
                                               this, d, PERIOD);    timer.start();
        System.out.println(">>> 定时器已经启动.");
      }  public void contextDestroyed(ServletContextEvent event) {
        System.out.println(">>> 定时器销毁.");
        try {
          timer.stop();
          timer.removeNotification(notificationId);
          System.out.println(">>> 定时器已经停止.");
        }
        catch (InstanceNotFoundException e) {
          e.printStackTrace();
        }
      }  /* callback method */
      public void handleNotification(Notification notif, Object handback) {
        System.out.println("计划任务开始执行");
        try {
          CallPlan.execuMethod();
        }
        catch (Exception e) {
          System.out.println(e.toString());
        }
        System.out.println(">>> " + (new Date()) + " 定时器接到执行通知=" +
                           notif + ", 退回初始状态=" + handback);
      }
    }