Ejemplo n.º 1
0
  /** 启动分发线程, 使用传入的scheduler线程池. */
  public void start(ScheduledExecutorService scheduledThreadPool) {
    scriptExecutor.loadFromFile(scriptPath);

    dispatchJob =
        scheduledThreadPool.scheduleAtFixedRate(
            new WrapExceptionRunnable(this), 0, intervalMillis, TimeUnit.MILLISECONDS);
  }
Ejemplo n.º 2
0
 /** 以当前时间为参数执行Lua Script分发任务。 */
 @Override
 public void run() {
   try {
     long currTime = System.currentTimeMillis();
     List<String> args =
         Lists.newArrayList(
             String.valueOf(currTime), String.valueOf(reliable), String.valueOf(jobTimeoutSecs));
     scriptExecutor.execute(keys, args);
   } catch (Throwable e) {
     // catch any exception, because the scheduled thread will break if the exception thrown
     // outside.
     logger.error("Unexpected error occurred in task", e);
   }
 }