@Test
 public void testScheduledAnnotation() throws Exception {
   ScriptManager sm = new ScriptManager();
   sm.setGlobalClassListener(new ScheduledTaskClassListenerTestAdapter(cronService));
   sm.loadDirectory(new File(FILE_TEST_DATA_DIR));
   assertEquals(cronService.getRunnables().size(), 1);
   sm.shutdown();
   assertEquals(cronService.getRunnables().size(), 0);
 }
 @BeforeClass
 public void initCronService() throws Exception {
   Constructor<CronService> constructor = CronService.class.getDeclaredConstructor();
   constructor.setAccessible(true);
   cronService = constructor.newInstance();
   cronService.init(CurrentThreadRunnableRunner.class);
 }
  /**
   * this function is called, when a new thread starts if this thread is the thread of getInstance,
   * then this is the shutdown hook and we save all data and disconnect all clients. after this
   * thread ends, the server will completely exit if this is not the thread of getInstance, then
   * this is a countdown thread. we start the countdown, and when we finished it, and it was not
   * aborted, we tell the shutdown-hook why we call exit, and then call exit when the exit status of
   * the server is 1, startServer.sh / startServer.bat will restart the server.
   */
  @Override
  public void run() {
    try {
      NetConnector.getInstance().shutdown();
    } catch (Throwable t) {
      log.error("Can't shutdown NetConnector", t);
    }
    /* Shuting down DB connections */
    try {
      DatabaseFactory.shutdown();
    } catch (Throwable t) {
      log.error("Can't shutdown DatabaseFactory", t);
    }

    // shutdown cron service prior to threadpool shutdown
    CronService.getInstance().shutdown();

    /* Shuting down threadpools */
    try {
      ThreadPoolManager.getInstance().shutdown();
    } catch (Throwable t) {
      log.error("Can't shutdown ThreadPoolManager", t);
    }

    // Do system exit
    if (restartOnly) {
      Runtime.getRuntime().halt(ExitCode.CODE_RESTART);
    } else {
      Runtime.getRuntime().halt(ExitCode.CODE_NORMAL);
    }
  }
  public static void ScheduleCron() {
    CronService.getInstance()
        .schedule(
            new Runnable() {

              @Override
              public void run() {
                startEvent(); // To change body of generated methods, choose Tools | Templates.
              }
            },
            PIG_EVENT_SCHEDULE);
    log.info("Pig Event start to:" + EventsConfig.PIG_EVENT_SCHEDULE + " duration 30 min");
  }
 public void start() {
   String[] times = AutoGroupConfig.IRONWALL_TIMES.split("\\|");
   for (String cron : times) {
     CronService.getInstance()
         .schedule(
             new Runnable() {
               @Override
               public void run() {
                 startIronWallRegistration();
               }
             },
             cron);
     log.info(
         "Scheduled Iron Wall WarFront based on cron expression: "
             + cron
             + " Duration: "
             + AutoGroupConfig.IRONWALL_TIMER
             + " in minutes");
   }
 }
 @AfterClass
 public void afterTest() throws Exception {
   cronService.shutdown();
 }