예제 #1
0
  /** {@inheritDoc} <br> */
  @Override
  protected <T> Callable<T> toCallable(final SlideCallback<T> task) {
    Args.check(0 < threadNum, "'ThreadNum' cannot be less than zero.");
    return new Callable<T>() {
      @Override
      public T call() throws Exception {
        int exp = (int) TimeUnit.MILLISECONDS.toSeconds(intervalMilliseconds) - 1; // 早1秒失效
        for (int i = 1; i <= threadNum; i++) {
          String key = keyPrefix + i;
          boolean add = cacheService.add(key, 1, exp);
          if (add) return task.call();
        }

        Thread.sleep(intervalMilliseconds); // TODO 寻找更好的方案
        return call();
      }
    };
  }
예제 #2
0
 /** @param intervalMilliseconds 要设置的 intervalMilliseconds */
 public void setIntervalMilliseconds(long intervalMilliseconds) {
   Args.check(
       0 < intervalMilliseconds, "'intervalMilliseconds' should be a value greater than zero.");
   this.intervalMilliseconds = intervalMilliseconds;
 }