Package enterprise.web.tookit.scheduling

Source Code of enterprise.web.tookit.scheduling.TaskSchedulerImpl

package enterprise.web.tookit.scheduling;

import java.util.Date;

import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerService;

import org.apache.log4j.Logger;

@Stateless(mappedName = "TaskScheduler")
public class TaskSchedulerImpl implements TaskScheduler {

  @Resource
  private TimerService timerService;

  /**
   * log
   */
  private static Logger log = Logger.getLogger(TaskSchedulerImpl.class);

  /**
   * Default constructor.
   */
  public TaskSchedulerImpl() {
  }

  @Timeout
  public void scheduleTask(final Timer timer) {
    log.info(timer.getInfo());
    System.out.println("TIMER");
  }

  @Override
  public void cancelScheduling() {
    for (Object currentTimer : timerService.getTimers()) {
      Timer timer = (Timer) currentTimer;
      log.info("Cancel Timer ...." + timer.getInfo());
      timer.cancel();
    }
  }

  @Override
  public void createTimer() {
    timerService.createTimer(new Date(System.currentTimeMillis() + 100000), "My first Timer service....");

  }

}
TOP

Related Classes of enterprise.web.tookit.scheduling.TaskSchedulerImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.