本文整理汇总了Java中org.threadly.util.Clock.accurateForwardProgressingMillis方法的典型用法代码示例。如果您正苦于以下问题:Java Clock.accurateForwardProgressingMillis方法的具体用法?Java Clock.accurateForwardProgressingMillis怎么用?Java Clock.accurateForwardProgressingMillis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.threadly.util.Clock
的用法示例。
在下文中一共展示了Clock.accurateForwardProgressingMillis方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setMaxScriptStepRateTest
import org.threadly.util.Clock; //导入方法依赖的package包/类
@Test
public void setMaxScriptStepRateTest() throws InterruptedException, ExecutionException {
int testSteps = 5;
SequentialScriptBuilder builder = new SequentialScriptBuilder();
builder.setMaxScriptStepRate(testSteps * 10);
for (int i = 0; i < testSteps + 1; i++) {
builder.addStep(new TestStep());
}
ExecutableScript script = builder.build();
long start = Clock.accurateForwardProgressingMillis();
FutureUtils.blockTillAllCompleteOrFirstError(script.startScript());
long end = Clock.accurateForwardProgressingMillis();
assertTrue(end - start >= 100);
}
示例2: run
import org.threadly.util.Clock; //导入方法依赖的package包/类
@Override
public void run() {
long startTime = threadRunTime > 0 ? Clock.accurateForwardProgressingMillis() : -1;
if (run) {
countArray.incrementAndGet(index);
long scheduleDelay;
if (DIFFER_SCHEDULE_TIME) {
scheduleDelay = AbstractSchedulerScheduleBenchmark.this.scheduleDelay * (index / 2);
} else {
scheduleDelay = AbstractSchedulerScheduleBenchmark.this.scheduleDelay;
}
doThreadWork(startTime);
getScheduler().schedule(this, scheduleDelay);
}
}
示例3: 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());
}
示例4: blockTillAllCompleteOrFirstError
import org.threadly.util.Clock; //导入方法依赖的package包/类
/**
* This call blocks till all futures in the list have completed. If the future completed with
* an error an {@link ExecutionException} is thrown. If this exception is thrown, all futures
* may or may not be completed, the exception is thrown as soon as it is hit. There also may be
* additional futures that errored (but were not hit yet).
*
* @since 4.0.0
* @param futures Structure of futures to iterate over
* @param timeoutInMillis timeout to wait for futures to complete in milliseconds
* @throws InterruptedException Thrown if thread is interrupted while waiting on future
* @throws TimeoutException Thrown if the timeout elapsed while waiting on futures to complete
* @throws ExecutionException Thrown if future throws exception on .get() call
*/
public static void blockTillAllCompleteOrFirstError(Iterable<? extends Future<?>> futures, long timeoutInMillis)
throws InterruptedException, TimeoutException, ExecutionException {
if (futures == null) {
return;
}
Iterator<? extends Future<?>> it = futures.iterator();
long startTime = Clock.accurateForwardProgressingMillis();
long remainingTime;
while (it.hasNext() &&
(remainingTime = timeoutInMillis - (Clock.lastKnownForwardProgressingMillis() - startTime)) > 0) {
it.next().get(remainingTime, TimeUnit.MILLISECONDS);
}
if (it.hasNext()) {
throw new TimeoutException();
}
}
示例5: awaitTerminationTest
import org.threadly.util.Clock; //导入方法依赖的package包/类
@Test
public void awaitTerminationTest() throws InterruptedException {
PrioritySchedulerServiceFactory factory = getPrioritySchedulerFactory();
try {
PriorityScheduler scheduler = factory.makePriorityScheduler(1);
TestRunnable tr = new TestRunnable(DELAY_TIME * 2);
long start = Clock.accurateForwardProgressingMillis();
scheduler.execute(tr);
tr.blockTillStarted();
scheduler.shutdown();
scheduler.awaitTermination();
long stop = Clock.accurateForwardProgressingMillis();
assertTrue(stop - start >= (DELAY_TIME * 2) - 10);
} finally {
factory.shutdown();
}
}
示例6: blockTillRunTest
import org.threadly.util.Clock; //导入方法依赖的package包/类
@Test
public void blockTillRunTest() {
TestRunnable tr = new TestRunnable() {
private boolean firstRun = true;
@Override
public void handleRunStart() throws InterruptedException {
if (firstRun) {
firstRun = false;
TestUtils.sleep(DELAY_TIME);
run();
}
}
};
new Thread(tr).start();
long startTime = Clock.accurateForwardProgressingMillis();
tr.blockTillFinished(1000, 2);
long endTime = Clock.accurateForwardProgressingMillis();
assertTrue(endTime - startTime >= (DELAY_TIME - ALLOWED_VARIANCE));
}
示例7: trackStart
import org.threadly.util.Clock; //导入方法依赖的package包/类
public void trackStart(Pair<Thread, Runnable> taskPair, long expectedRunTime) {
// get start time before any operations for hopefully more accurate execution delay
long startTime = Clock.accurateForwardProgressingMillis();
queuedTaskCount.decrement();
totalExecutionCount.increment();
synchronized (runDelays) {
runDelays.addLast(startTime - expectedRunTime);
if (runDelays.size() > maxStatisticWindowSize) {
runDelays.removeFirst();
}
}
// get possibly newer time so we don't penalize stats tracking as duration
runningTasks.put(taskPair, Clock.lastKnownForwardProgressingMillis());
}
示例8: runScript
import org.threadly.util.Clock; //导入方法依赖的package包/类
/**
* Starts the execution of the script. This executes and reports the output to
* {@link #out(String)}. That output includes tracked details during execution like speed and
* success or failures.
*
* @return Number of failed steps
* @throws Exception Thrown if error or interruption while waiting for script
*/
protected int runScript() throws Exception {
long start = Clock.accurateForwardProgressingMillis();
List<ListenableFuture<StepResult>> futures = script.startScript();
List<StepResult> fails = StepResultCollectionUtils.getAllFailedResults(futures);
long end = Clock.accurateForwardProgressingMillis();
handleRunFinish(futures, fails, end - start);
return fails.size();
}
示例9: main
import org.threadly.util.Clock; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
if (args.length < 1) {
System.err.println("Usage: java -cp build/libs/heapDumpAnalyzer.java " +
Parse.class.getName() + " dump.hprof");
System.exit(1);
}
Profiler pf = new Profiler(10);
PriorityScheduler scheduler = new PriorityScheduler(Runtime.getRuntime().availableProcessors() * 2);
long start = Clock.accurateForwardProgressingMillis();
try {
HprofParser parser = new HprofParser(scheduler, new File(args[0]));
if(args.length >= 2) {
pf.start();
}
parser.parse();
System.out.println("ParseTime:"+(Clock.accurateForwardProgressingMillis()-start));
System.out.println("---------------------");
long at = Clock.accurateForwardProgressingMillis();
parser.analyze();
System.out.println("---------------------");
System.out.println("AnalyseTime:"+(Clock.accurateForwardProgressingMillis()-at));
} finally {
if(args.length >= 2) {
pf.stop();
File f = File.createTempFile("profile", "out");
RandomAccessFile raf = new RandomAccessFile(f, "rw");
raf.write(pf.dump().getBytes());
raf.close();
}
System.out.println("---------------------");
System.out.println("TotalTime:"+(Clock.accurateForwardProgressingMillis()-start));
System.gc();
System.out.println("---------------------");
System.out.println("Used Memory:" + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
scheduler.shutdown();
}
}
示例10: connect
import org.threadly.util.Clock; //导入方法依赖的package包/类
@Override
public ListenableFuture<Boolean> connect(){
if(startedConnection.compareAndSet(false, true)) {
try {
channel.connect(remoteAddress);
connectExpiresAt = maxConnectionTime + Clock.accurateForwardProgressingMillis();
se.setClientOperations(this);
se.watchFuture(connectionFuture, maxConnectionTime);
} catch (Exception e) {
connectionFuture.setFailure(e);
close();
}
}
return connectionFuture;
}
示例11: 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;
}
示例12: 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;
}
}
}
}
示例13: run
import org.threadly.util.Clock; //导入方法依赖的package包/类
@Override
public void run() {
if (run) {
long startTime = threadRunTime > 0 ? Clock.accurateForwardProgressingMillis() : -1;
countArray.incrementAndGet(index);
doThreadWork(startTime);
getScheduler().execute(this);
}
}
示例14: run
import org.threadly.util.Clock; //导入方法依赖的package包/类
@Override
public void run() {
if (run) {
long startTime = threadRunTime > 0 ? Clock.accurateForwardProgressingMillis() : -1;
countArray.incrementAndGet(index);
doThreadWork(startTime);
}
}
示例15: 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());
}