List of usage examples for java.util.concurrent TimeUnit NANOSECONDS
TimeUnit NANOSECONDS
To view the source code for java.util.concurrent TimeUnit NANOSECONDS.
Click Source Link
From source file:objectpoolbenchmark.PoolBenchmarkTest.java
@Test public void benchmark() throws Exception { int size = 16; // introduce the possibility of a little blocking CommonPool storm = new StormPool(size); CommonPool basic = new BasicPool(size); CommonPool array = new ABQPool(size); for (int at = 0; at != 50; ++at) { benchmark(storm);//w ww .j a v a2s . co m benchmark(basic); benchmark(array); } long stormN = 0; long basicN = 0; long arrayN = 0; for (int at = 0; at != 30; ++at) { stormN += benchmark(storm); basicN += benchmark(basic); arrayN += benchmark(array); } System.out.println("storm = " + ((double) (TimeUnit.NANOSECONDS.toMillis(stormN))) / 1000.00); System.out.println("basic = " + ((double) (TimeUnit.NANOSECONDS.toMillis(basicN))) / 1000.00); System.out.println("array = " + ((double) (TimeUnit.NANOSECONDS.toMillis(arrayN))) / 1000.00); }
From source file:com.proofpoint.stats.TimeStat.java
public void add(double value, TimeUnit timeUnit) { add(new Duration(value, timeUnit).roundTo(TimeUnit.NANOSECONDS)); }
From source file:Main.java
/** * If the given time (based on {@link System#nanoTime}) has passed, throw a TimeoutException. * Otherwise, invoke {@link Object#wait(long, int)} on the given object, which may return due to * a {@code notify()} call, the timeout being reached, or a spurious wake-up. To distinguish between * these possibilities, clients should wrap this call in a while loop: * {@code long t = futureTimeNanos(...); while (!condition) waitUntilNanos(lock, t);} * This loop either completes if the condition is satisfied or throws an appropriate exception * due to an interrupt or timeout.//from www . j a v a2 s.c om * @param obj Object whose {@code wait()} method will be invoked. Must be locked by the current thread. * @param futureTime A nanosecond time value based on {@code System.nanoTime()} after which * this method should no longer invoke {@code obj.wait()}. * @throws InterruptedException If the wait is interrupted. * @throws TimeoutException If, at invocation time, {@code futureTime} is in the past. * @see #futureTimeNanos */ public static void waitUntilNanos(Object obj, long futureTime) throws InterruptedException, TimeoutException { long delta = futureTime - System.nanoTime(); if (delta > 0) { TimeUnit.NANOSECONDS.timedWait(obj, delta); } else { throw new TimeoutException(); } }
From source file:io.airlift.stats.TimeStat.java
public void add(Duration duration) { add((long) duration.getValue(TimeUnit.NANOSECONDS)); }
From source file:com.mgmtp.perfload.core.client.util.concurrent.DelayingExecutorServiceTest.java
@Test public void testWithoutDelay() throws InterruptedException, BrokenBarrierException { DelayingExecutorService execSrv = new DelayingExecutorService(); final StopWatch sw = new StopWatch(); final CyclicBarrier stopBarrier = new CyclicBarrier(11, new Runnable() { @Override/* w ww . j av a 2 s .c om*/ public void run() { sw.stop(); } }); sw.start(); for (int i = 0; i < 10; ++i) { Runnable r = new Runnable() { @Override public void run() { try { Thread.sleep(1L); stopBarrier.await(); } catch (Exception ex) { throw new AssertionError(ex); } } }; ScheduledFuture<?> future = execSrv.schedule(r, 0L, TimeUnit.NANOSECONDS); // compare with epsilon to make up for bad accuracy assertTrue(abs(future.getDelay(TimeUnit.MILLISECONDS)) < EPSILON); } stopBarrier.await(); assertTrue(sw.getTime() < EPSILON); }
From source file:com.proofpoint.stats.TimeStat.java
public void add(Duration duration) { add(duration.roundTo(TimeUnit.NANOSECONDS)); }
From source file:CollectionTest.java
public Timestamp() { this(TimeUnit.NANOSECONDS); }
From source file:de.htwg_konstanz.in.uce.hp.parallel.integration_test.SourceMock.java
@Override protected boolean waitForTarget() { MediatorBrowser browser = new MediatorBrowser(mediatorAddress); long start = TimeUnit.NANOSECONDS.toSeconds(System.nanoTime()); try {/* w w w. j ava 2 s. c o m*/ while ((TimeUnit.NANOSECONDS.toSeconds(System.nanoTime()) - start) <= WAIT_TIME_FOR_TARGET && !browser.getSetOfRegisteredTargets().contains(id)) { try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return false; } } return browser.getSetOfRegisteredTargets().contains(id); } catch (IOException e) { e.printStackTrace(); return false; } }
From source file:at.ac.univie.isc.asio.tool.Timeout.java
/** * Get the timeout value converted to the given time-unit, or the fallback value, if the timeout * is not defined.// w w w .ja v a 2s . c o m * @param unit target time-unit * @param fallback default value * @return literal value of timeout in the target unit */ public long getAs(@Nonnull final TimeUnit unit, final long fallback) { return defined ? unit.convert(timeoutInNanos, TimeUnit.NANOSECONDS) : fallback; }
From source file:rmblworx.tools.timey.SimpleTimerTest.java
/** * Test method for {@link SimpleTimer#resetStopwatch()}. *///from www . j a v a 2s . com @Test public final void testResetStopwatch() { this.timer.startStopwatch(1, TimeUnit.NANOSECONDS); assertTrue(this.timer.resetStopwatch()); }