コード例 #1
0
ファイル: TimeScheduler2.java プロジェクト: jiwils/JGroups
  protected void _run() {
    ConcurrentNavigableMap<Long, Entry>
        head_map; // head_map = entries which are <= curr time (ready to be executed)
    if (!(head_map = tasks.headMap(System.currentTimeMillis(), true)).isEmpty()) {
      final List<Long> keys = new LinkedList<Long>();
      for (Map.Entry<Long, Entry> entry : head_map.entrySet()) {
        final Long key = entry.getKey();
        final Entry val = entry.getValue();
        pool.execute(
            new Runnable() {
              public void run() {
                val.execute();
              }
            });
        keys.add(key);
      }
      tasks.keySet().removeAll(keys);
    }

    if (tasks.isEmpty()) {
      no_tasks.compareAndSet(false, true);
      waitFor(); // sleeps until time elapses, or a task with a lower execution time is added
    } else
      waitUntilNextExecution(); // waits until next execution, or a task with a lower execution time
    // is added
  }
コード例 #2
0
ファイル: TimeScheduler2.java プロジェクト: jiwils/JGroups
  /**
   * Stops the timer, cancelling all tasks
   *
   * @throws InterruptedException if interrupted while waiting for thread to return
   */
  public void stop() {
    stopRunner();

    java.util.List<Runnable> remaining_tasks = pool.shutdownNow();
    for (Runnable task : remaining_tasks) {
      if (task instanceof Future) {
        Future future = (Future) task;
        future.cancel(true);
      }
    }
    pool.getQueue().clear();
    try {
      pool.awaitTermination(Global.THREADPOOL_SHUTDOWN_WAIT_TIME, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
    }

    for (Entry entry : tasks.values()) entry.cancel();
    tasks.clear();
  }
コード例 #3
0
ファイル: TimeScheduler2.java プロジェクト: jiwils/JGroups
 protected void init() {
   if (threadDecorator != null) pool.setThreadDecorator(threadDecorator);
   // pool.allowCoreThreadTimeOut(true);
   startRunner();
 }
コード例 #4
0
ファイル: TimeScheduler2.java プロジェクト: jiwils/JGroups
 public boolean isShutdown() {
   return pool.isShutdown();
 }
コード例 #5
0
ファイル: TimeScheduler2.java プロジェクト: jiwils/JGroups
 public int getQueueSize() {
   return pool.getQueue().size();
 }
コード例 #6
0
ファイル: TimeScheduler2.java プロジェクト: jiwils/JGroups
 public void setKeepAliveTime(long time) {
   pool.setKeepAliveTime(time, TimeUnit.MILLISECONDS);
 }
コード例 #7
0
ファイル: TimeScheduler2.java プロジェクト: jiwils/JGroups
 public int getCurrentThreads() {
   return pool.getPoolSize();
 }
コード例 #8
0
ファイル: TimeScheduler2.java プロジェクト: jiwils/JGroups
 public void setMaxThreads(int size) {
   pool.setMaximumPoolSize(size);
 }
コード例 #9
0
ファイル: TimeScheduler2.java プロジェクト: jiwils/JGroups
 public long getKeepAliveTime() {
   return pool.getKeepAliveTime(TimeUnit.MILLISECONDS);
 }
コード例 #10
0
ファイル: TimeScheduler2.java プロジェクト: jiwils/JGroups
 public int getMaxThreads() {
   return pool.getMaximumPoolSize();
 }
コード例 #11
0
ファイル: TimeScheduler2.java プロジェクト: jiwils/JGroups
 public void setMinThreads(int size) {
   pool.setCorePoolSize(size);
 }
コード例 #12
0
ファイル: TimeScheduler2.java プロジェクト: jiwils/JGroups
 public int getMinThreads() {
   return pool.getCorePoolSize();
 }
コード例 #13
0
ファイル: TimeScheduler2.java プロジェクト: jiwils/JGroups
 public void setThreadFactory(ThreadFactory factory) {
   pool.setThreadFactory(factory);
 }
コード例 #14
0
ファイル: TimeScheduler2.java プロジェクト: jiwils/JGroups
 public void setThreadDecorator(ThreadDecorator threadDecorator) {
   this.threadDecorator = threadDecorator;
   pool.setThreadDecorator(threadDecorator);
 }