List of usage examples for java.util.concurrent TimeUnit MICROSECONDS
TimeUnit MICROSECONDS
To view the source code for java.util.concurrent TimeUnit MICROSECONDS.
Click Source Link
From source file:it.mbcraft.command_server.engine.CommandServer.java
/** * Stops the server.//from w ww . j a v a2s . co m */ @Override public void stop() { try { wasStopped = true; server.shutdown(1, TimeUnit.MICROSECONDS); server.awaitTermination(1, TimeUnit.MINUTES); server = null; } catch (InterruptedException ex) { if (!wasStopped) { Logger.getLogger(CommandServer.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalMetrics.java
@Override public String toString() { // Build a pretty table of metrics data. // Append headers final StringBuilder sb = new StringBuilder("Traversal Metrics\n") .append(String.format("%-50s %21s %11s %15s %8s", HEADERS)); sb.append(/*from w w w .j av a2 s.co m*/ "\n============================================================================================================="); appendMetrics(this.computedMetrics.values(), sb, 0); // Append total duration sb.append(String.format("%n%50s %21s %11s %15.3f %8s", ">TOTAL", "-", "-", getDuration(TimeUnit.MICROSECONDS) / 1000.0, "-")); return sb.toString(); }
From source file:cosmos.results.integration.CosmosIntegrationTest.java
@Test public void testWiki1() throws Exception { // Get the same wiki 3 times List<Thread> threads = Lists.newArrayList(); final List<Long> timings = Lists.newArrayList(); // Preload/*from www .j av a2 s . co m*/ Stopwatch sw = new Stopwatch(); sw.start(); getWiki1(); sw.stop(); long origLength = sw.elapsed(TimeUnit.MICROSECONDS); for (int i = 0; i < 3; i++) { threads.add(new Thread(new Runnable() { public void run() { try { Stopwatch sw = new Stopwatch(); sw.start(); getWiki1(); sw.stop(); timings.add(sw.elapsed(TimeUnit.MICROSECONDS)); } catch (Exception e) { throw new RuntimeException(e); } } })); } long start = System.currentTimeMillis(); for (Thread t : threads) { t.start(); } for (Thread t : threads) { t.join(); } long end = System.currentTimeMillis(); for (Long duration : timings) { Assert.assertTrue(origLength > duration); } }
From source file:org.cloudifysource.dsl.download.ResourceDownloaderTest.java
@Test public void testTimeout() { // Try doGet with very short timeout. try {// ww w . java2 s. c o m rdf.get(RESOURCE_URL, RESOURCE_DESTINATION, false, 1, TimeUnit.MICROSECONDS); Assert.fail("Expected timeout exception."); } catch (TimeoutException e) { // test passed. } catch (ResourceDownloadException e) { Assert.fail("Expecting timeout exception. got " + e.getMessage()); } }
From source file:io.tilt.minka.spectator.Locks.java
/** * A race between runner candidates, first acquiring the lock will disable others to run. * i.e. run only if other duty with same Lock Is Not also running. * /* w w w. java 2 s . c om*/ * @param lockName a name unique within the timewindow the runner intends to race for run * @param runnable this is executed within the same caller's thread * @return whether or not the runner acquired the lock and run */ public boolean runOnLockRace(final String lockName, final Runnable runnable) { return createLock(lockName, runnable, true, 0, TimeUnit.MICROSECONDS); }
From source file:org.apache.tinkerpop.gremlin.process.util.metric.StandardTraversalMetrics.java
private void appendMetrics(final Collection<? extends Metrics> metrics, final StringBuilder sb, final int indent) { // Append each StepMetric's row. indexToLabelMap values are ordered by index. for (Metrics m : metrics) { String rowName = m.getName(); for (int ii = 0; ii < indent; ii++) { rowName = " " + rowName; }/*www . j a va 2 s. c o m*/ rowName = StringUtils.abbreviate(rowName, 50); final long itemCount = m.getCount(TraversalMetrics.ELEMENT_COUNT_ID); final long traverserCount = m.getCount(TraversalMetrics.TRAVERSER_COUNT_ID); Double percentDur = (Double) m.getAnnotation(TraversalMetrics.PERCENT_DURATION_KEY); if (percentDur != null) { sb.append(String.format("%n%-50s %21d %11d %15.3f %8.2f", rowName, itemCount, traverserCount, m.getDuration(TimeUnit.MICROSECONDS) / 1000.0, percentDur)); } else { sb.append(String.format("%n%-50s %21d %11d %15.3f", rowName, itemCount, traverserCount, m.getDuration(TimeUnit.MICROSECONDS) / 1000.0)); } appendMetrics(m.getNested(), sb, indent + 1); } }
From source file:org.mortbay.jetty.load.generator.listeners.CollectorServer.java
@Override public void onResourceNode(Resource.Info info) { String path = info.getResource().getPath(); Recorder recorder = recorderPerPath.get(path); if (recorder == null) { recorder = new Recorder(TimeUnit.MICROSECONDS.toNanos(1), // TimeUnit.MINUTES.toNanos(1), // 3);//from ww w . j a v a 2 s. c om recorderPerPath.put(path, recorder); } long time = info.getResponseTime() - info.getRequestTime(); try { recorder.recordValue(time); } catch (ArrayIndexOutOfBoundsException e) { LOGGER.warn("skip error recording time {}, {}", time, e.getMessage()); } }
From source file:com.linkedin.pinot.core.query.scheduler.MultiLevelPriorityQueue.java
/** * Blocking call to read the next query in order of priority * @return/*from w ww. j a v a 2 s . co m*/ */ @Override public @Nullable SchedulerQueryContext take() { queueLock.lock(); try { while (true) { SchedulerQueryContext schedulerQueryContext; while ((schedulerQueryContext = takeNextInternal()) == null) { try { queryReaderCondition.await(wakeUpTimeMicros, TimeUnit.MICROSECONDS); } catch (InterruptedException e) { return null; } } return schedulerQueryContext; } } finally { queueLock.unlock(); } }
From source file:io.druid.benchmark.indexing.IndexPersistBenchmark.java
@Benchmark @BenchmarkMode(Mode.AverageTime)/*from w w w . j a v a 2 s . com*/ @OutputTimeUnit(TimeUnit.MICROSECONDS) public void persistV9(Blackhole blackhole) throws Exception { File tmpDir = Files.createTempDir(); log.info("Using temp dir: " + tmpDir.getAbsolutePath()); try { File indexFile = INDEX_MERGER_V9.persist(incIndex, tmpDir, new IndexSpec()); blackhole.consume(indexFile); } finally { FileUtils.deleteDirectory(tmpDir); } }
From source file:org.wisdom.maven.utils.Properties2HoconConverterTest.java
@Test public void testTypes() throws IOException { File props = new File(root, "/types.properties"); File hocon = Properties2HoconConverter.convert(props, true); PropertiesConfiguration properties = loadPropertiesWithApacheConfiguration(props); Config config = load(hocon);//from w w w .j a v a2s .co m assertThat(properties).isNotNull(); assertThat(properties.isEmpty()).isFalse(); assertThat(config.isEmpty()).isFalse(); assertThat(config.getString("conf.string")).isEqualTo("foo"); assertThat(config.getString("conf.int")).isEqualTo("1"); assertThat(config.getInt("conf.int")).isEqualTo(1); assertThat(config.getNumber("conf.int")).isEqualTo(1); assertThat(config.getString("conf.float")).isEqualTo("1.1"); assertThat(config.getNumber("conf.float")).isEqualTo(1.1); assertThat(config.getNumber("conf.float")).isEqualTo(1.1d); assertThat(config.getDouble("conf.float")).isEqualTo(1.1d); assertThat(config.getBoolean("conf.boolean.true")).isTrue(); assertThat(config.getBoolean("conf.boolean.false")).isFalse(); assertThat(config.getBoolean("conf.boolean.yes")).isTrue(); assertThat(config.getBoolean("conf.boolean.no")).isFalse(); assertThat(config.getBoolean("conf.boolean.on")).isTrue(); assertThat(config.getBoolean("conf.boolean.off")).isFalse(); assertThat(config.getDuration("conf.unit.time", TimeUnit.MILLISECONDS)).isEqualTo(10l); assertThat(config.getDuration("conf.unit.time", TimeUnit.MICROSECONDS)).isEqualTo(10000l); assertThat(config.getBytes("conf.unit.size")).isEqualTo(512 * 1024); assertThat(config.getBytes("conf.unit.size2")).isEqualTo(10); assertThat(config.getIntList("conf.list.int")).containsExactly(1, 2, 3); assertThat(config.getStringList("conf.list.string")).containsExactly("a", "b", "c"); assertThat(config.hasPath("conf.missing")).isFalse(); assertThat(config.getString("conf.quotes")).isEqualTo("http://example.com"); }