当前位置: 首页>>代码示例>>Java>>正文


Java Clock.lastKnownForwardProgressingMillis方法代码示例

本文整理汇总了Java中org.threadly.util.Clock.lastKnownForwardProgressingMillis方法的典型用法代码示例。如果您正苦于以下问题:Java Clock.lastKnownForwardProgressingMillis方法的具体用法?Java Clock.lastKnownForwardProgressingMillis怎么用?Java Clock.lastKnownForwardProgressingMillis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.threadly.util.Clock的用法示例。


在下文中一共展示了Clock.lastKnownForwardProgressingMillis方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: removeRunnableTest

import org.threadly.util.Clock; //导入方法依赖的package包/类
@Test
public void removeRunnableTest() {
  TestRunnable runnable = new TestRunnable();
  OneTimeTaskWrapper task = new OneTimeTaskWrapper(runnable, null, 
                                                   Clock.lastKnownForwardProgressingMillis());
  
  assertFalse(queueSet.remove(runnable));
  
  queueSet.executeQueue.add(task);

  assertTrue(queueSet.remove(runnable));
  assertFalse(queueSet.remove(runnable));
  
  queueSet.scheduleQueue.addFirst(task);

  assertTrue(queueSet.remove(runnable));
  assertFalse(queueSet.remove(runnable));
}
 
开发者ID:threadly,项目名称:threadly,代码行数:19,代码来源:PrioritySchedulerQueueSetTest.java

示例2: getLongRunningTasksQty

import org.threadly.util.Clock; //导入方法依赖的package包/类
@Override
public int getLongRunningTasksQty(long durationLimitMillis) {
  int result = 0;

  if (statsContainer.accurateTime) {
    // ensure clock is updated before loop
    Clock.accurateForwardProgressingMillis();
  }
  for (Long l : statsContainer.runningTasks.values()) {
    if (Clock.lastKnownForwardProgressingMillis() - l > durationLimitMillis) {
      result++;
    }
  }
  
  return result;
}
 
开发者ID:threadly,项目名称:threadly,代码行数:17,代码来源:ExecutorStatisticWrapper.java

示例3: RateLimiterExecutor

import org.threadly.util.Clock; //导入方法依赖的package包/类
/**
 * Constructs a new {@link RateLimiterExecutor}.  Tasks will be scheduled on the provided 
 * scheduler, so it is assumed that the scheduler will have enough threads to handle the 
 * average permit amount per task, per second.  
 * <p>
 * This constructor accepts a maximum schedule delay.  If a task requires being scheduled out 
 * beyond this delay, then the provided {@link RejectedExecutionHandler} will be invoked.
 * 
 * @since 4.8.0
 * @param scheduler scheduler to schedule/execute tasks on
 * @param permitsPerSecond how many permits should be allowed per second
 * @param maxScheduleDelayMillis Maximum amount of time delay tasks in order to maintain rate
 * @param rejectedExecutionHandler Handler to accept tasks which could not be executed
 */
public RateLimiterExecutor(SubmitterScheduler scheduler, double permitsPerSecond, 
                           long maxScheduleDelayMillis, 
                           RejectedExecutionHandler rejectedExecutionHandler) {
  ArgumentVerifier.assertNotNull(scheduler, "scheduler");
  
  this.scheduler = scheduler;
  if (rejectedExecutionHandler == null) {
    rejectedExecutionHandler = RejectedExecutionHandler.THROW_REJECTED_EXECUTION_EXCEPTION;
  }
  this.rejectedExecutionHandler = rejectedExecutionHandler;
  this.permitLock = new Object();
  this.lastScheduleTime = Clock.lastKnownForwardProgressingMillis();
  setPermitsPerSecond(permitsPerSecond);
  setMaxScheduleDelayMillis(maxScheduleDelayMillis);
}
 
开发者ID:threadly,项目名称:threadly,代码行数:30,代码来源:RateLimiterExecutor.java

示例4: removeCallableTest

import org.threadly.util.Clock; //导入方法依赖的package包/类
@Test
public void removeCallableTest() {
  TestCallable callable = new TestCallable();
  OneTimeTaskWrapper task = new OneTimeTaskWrapper(new ListenableFutureTask<>(false, callable), 
                                                   null, Clock.lastKnownForwardProgressingMillis());
  
  assertFalse(queueSet.remove(callable));
  
  queueSet.executeQueue.add(task);

  assertTrue(queueSet.remove(callable));
  assertFalse(queueSet.remove(callable));
  
  queueSet.scheduleQueue.addFirst(task);

  assertTrue(queueSet.remove(callable));
  assertFalse(queueSet.remove(callable));
}
 
开发者ID:threadly,项目名称:threadly,代码行数:19,代码来源:PrioritySchedulerQueueSetTest.java

示例5: getNextReadyTaskScheduledAheadOfExecuteTest

import org.threadly.util.Clock; //导入方法依赖的package包/类
@Test
 public void getNextReadyTaskScheduledAheadOfExecuteTest() {
   TaskWrapper scheduleTask = new OneTimeTaskWrapper(DoNothingRunnable.instance(), 
                                                     queueManager.highPriorityQueueSet.scheduleQueue,
                                                     Clock.accurateForwardProgressingMillis());
   queueManager.highPriorityQueueSet.addScheduled(scheduleTask);
   TestUtils.blockTillClockAdvances();
   OneTimeTaskWrapper executeTask = new OneTimeTaskWrapper(DoNothingRunnable.instance(), 
                                                           queueManager.highPriorityQueueSet.executeQueue, 
                                                           Clock.lastKnownForwardProgressingMillis());
   queueManager.highPriorityQueueSet.addExecute(executeTask);

   assertTrue(scheduleTask == queueManager.getNextTask());
   assertTrue(scheduleTask == queueManager.getNextTask());  // schedule task has not been removed yet
// this should remove the schedule task so we can get the execute task
   assertTrue(scheduleTask.canExecute(executeTask.getExecuteReference()));
   assertTrue(executeTask == queueManager.getNextTask());
 }
 
开发者ID:threadly,项目名称:threadly,代码行数:19,代码来源:PrioritySchedulerQueueManagerTest.java

示例6: getNextReadyTask

import org.threadly.util.Clock; //导入方法依赖的package包/类
@Override
protected TaskWrapper getNextReadyTask() {
  TaskWrapper result = super.getNextReadyTask();
  
  // may not be a wrapper for internal tasks like shutdown
  if (result != null && result.getContainedRunnable() instanceof TaskStatWrapper) {
    long taskDelay = Clock.lastKnownForwardProgressingMillis() - result.getPureRunTime();
    TaskStatWrapper statWrapper = (TaskStatWrapper)result.getContainedRunnable();
    ConcurrentArrayList<Long> priorityStats = 
        statsManager.getExecutionDelaySamplesInternal(statWrapper.priority);

    synchronized (priorityStats.getModificationLock()) {
      priorityStats.add(taskDelay);
      statsManager.trimWindow(priorityStats);
    }
  }
  
  return result;
}
 
开发者ID:threadly,项目名称:threadly,代码行数:20,代码来源:NoThreadSchedulerStatisticTracker.java

示例7: cleanGraph

import org.threadly.util.Clock; //导入方法依赖的package包/类
/**
 * Traverses and cleans the graph.  This cleans up duplicate information like multiple join points.
 */
public void cleanGraph() {
  long startTime = Clock.lastKnownForwardProgressingMillis();
  while (true) {
    try {
      doCleanGraph();
      break;
    } catch (StackOverflowError e) {
      System.err.println("Attempting to clean graph..." + 
                           (Clock.lastKnownForwardProgressingMillis() - startTime) / 1000 + "seconds");
    }
  }
}
 
开发者ID:threadly,项目名称:ambushGUI,代码行数:16,代码来源:Node.java

示例8: hasConnectionTimedOut

import org.threadly.util.Clock; //导入方法依赖的package包/类
@Override
public boolean hasConnectionTimedOut() {
  if(! startedConnection.get() || channel.isConnected()) {
    return false;
  }
  return Clock.lastKnownForwardProgressingMillis() > connectExpiresAt || 
      Clock.accurateForwardProgressingMillis() > connectExpiresAt; 
}
 
开发者ID:threadly,项目名称:litesockets,代码行数:9,代码来源:TCPClient.java

示例9: doThreadWork

import org.threadly.util.Clock; //导入方法依赖的package包/类
/**
 * Small function to simulate threads actually doing something.
 * 
 * @param startReferenceTime Time thread started running (should be collected at absolute start)
 */
protected void doThreadWork(long startReferenceTime) {
  if (threadRunTime <= 0) {
    return;
  }
  
  int timeCheckIterations = 128;  // start high then decrease after first run
  int i = 0; // used to batch clock calls
  while (true) {
    // do some fake work, just to slow down clock calls without yielding the thread
    if (i % 2 == 0) {
      Math.pow(1024, 1024);
    } else {
      Math.log1p(1024);
    }
    if (Clock.lastKnownForwardProgressingMillis() - startReferenceTime >= threadRunTime) {
      break;
    } else if (++i == timeCheckIterations) {
      if (Clock.accurateForwardProgressingMillis() - startReferenceTime >= threadRunTime) {
        break;
      } else {
        timeCheckIterations = Math.max(10, timeCheckIterations / 2);
        i = 0;
      }
    }
  }
}
 
开发者ID:threadly,项目名称:threadly_benchmarks,代码行数:32,代码来源:AbstractSchedulerBenchmark.java

示例10: awaitTermination

import org.threadly.util.Clock; //导入方法依赖的package包/类
/**
 * Block until the thread pool has shutdown and all threads have been stopped.  If neither 
 * {@link #shutdown()} or {@link #shutdownNow()} is invoked, then this will block until the 
 * timeout is reached.
 * 
 * @param timeoutMillis time to block and wait for thread pool to shutdown
 * @return {@code true} if the pool has shutdown, false if timeout was reached
 * @throws InterruptedException Thrown if blocking thread is interrupted waiting for shutdown
 */
public boolean awaitTermination(long timeoutMillis) throws InterruptedException {
  long start = timeoutMillis < Long.MAX_VALUE ? 
    Clock.accurateForwardProgressingMillis() : Clock.lastKnownForwardProgressingMillis();
  synchronized (workerStopNotifyLock) {
    long remainingMillis;
    while ((! shutdownFinishing || currentPoolSize.get() > 0) && 
           (remainingMillis = timeoutMillis - (Clock.lastKnownForwardProgressingMillis() - start)) > 0) {
      workerStopNotifyLock.wait(remainingMillis);
    }
  }
  
  return shutdownFinishing && currentPoolSize.get() == 0;
}
 
开发者ID:threadly,项目名称:threadly,代码行数:23,代码来源:PriorityScheduler.java

示例11: getNextReadyTaskScheduledTest

import org.threadly.util.Clock; //导入方法依赖的package包/类
private void getNextReadyTaskScheduledTest(QueueSet queueSet) {
  TaskWrapper task = new OneTimeTaskWrapper(DoNothingRunnable.instance(), queueSet.scheduleQueue, 
                                            Clock.lastKnownForwardProgressingMillis());
  
  queueSet.addScheduled(task);
  
  assertTrue(task == queueManager.getNextTask());
}
 
开发者ID:threadly,项目名称:threadly,代码行数:9,代码来源:PrioritySchedulerQueueManagerTest.java

示例12: getScheduleDelay

import org.threadly.util.Clock; //导入方法依赖的package包/类
@Override
public long getScheduleDelay() {
  if (executing) {
    // this would only be likely if two threads were trying to run the same task
    return Long.MAX_VALUE;
  } else if (nextRunTime > Clock.lastKnownForwardProgressingMillis()) {
    return nextRunTime - Clock.accurateForwardProgressingMillis();
  } else {
    return 0;
  }
}
 
开发者ID:threadly,项目名称:threadly,代码行数:12,代码来源:AbstractPriorityScheduler.java

示例13: invokeAll

import org.threadly.util.Clock; //导入方法依赖的package包/类
@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks,
                                     long timeout, TimeUnit unit) throws InterruptedException {
  long timeoutInMs = unit.toMillis(timeout);
  long startTime = timeoutInMs < Long.MAX_VALUE ? Clock.accurateForwardProgressingMillis() : -1;
  List<Future<T>> resultList = new ArrayList<>(tasks.size());
  // execute all the tasks provided
  {
    Iterator<? extends Callable<T>> it = tasks.iterator();
    while (it.hasNext()) {
      Callable<T> c = it.next();
      if (c == null) {
        throw new NullPointerException();
      }
      
      ListenableFuture<T> lf = scheduler.submit(c);
      resultList.add(lf);
    }
  }
  // block till all tasks finish, or we reach our timeout
  if (timeoutInMs < Long.MAX_VALUE) {
    long remainingTime = timeoutInMs - (Clock.lastKnownForwardProgressingMillis() - startTime);
    try {
      FutureUtils.blockTillAllComplete(resultList, remainingTime);
    } catch (TimeoutException e) {
      FutureUtils.cancelIncompleteFutures(resultList, true);
    }
  } else {
    FutureUtils.blockTillAllComplete(resultList);
  }
  
  return resultList;
}
 
开发者ID:threadly,项目名称:threadly,代码行数:34,代码来源:AbstractExecutorServiceWrapper.java

示例14: getNextReadyTaskLowPriorityReadyFirstTest

import org.threadly.util.Clock; //导入方法依赖的package包/类
@Test
public void getNextReadyTaskLowPriorityReadyFirstTest() {
  TaskWrapper highTask = new OneTimeTaskWrapper(DoNothingRunnable.instance(), 
                                                queueManager.highPriorityQueueSet.scheduleQueue, 
                                                Clock.accurateForwardProgressingMillis() + (DELAY_TIME * 10));
  TaskWrapper lowTask = new OneTimeTaskWrapper(DoNothingRunnable.instance(), 
                                               queueManager.lowPriorityQueueSet.scheduleQueue, 
                                               Clock.lastKnownForwardProgressingMillis() + DELAY_TIME);
  queueManager.highPriorityQueueSet.addScheduled(highTask);
  queueManager.lowPriorityQueueSet.addScheduled(lowTask);

  assertTrue(lowTask == queueManager.getNextTask());
}
 
开发者ID:threadly,项目名称:threadly,代码行数:14,代码来源:PrioritySchedulerQueueManagerTest.java

示例15: addExecuteTest

import org.threadly.util.Clock; //导入方法依赖的package包/类
@Test
public void addExecuteTest() {
  OneTimeTaskWrapper task = new OneTimeTaskWrapper(DoNothingRunnable.instance(), null, 
                                                   Clock.lastKnownForwardProgressingMillis());
  
  queueSet.addExecute(task);
  
  assertEquals(1, queueSet.executeQueue.size());
  assertEquals(0, queueSet.scheduleQueue.size());
}
 
开发者ID:threadly,项目名称:threadly,代码行数:11,代码来源:PrioritySchedulerQueueSetTest.java


注:本文中的org.threadly.util.Clock.lastKnownForwardProgressingMillis方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。