Java Code Examples for java.util.concurrent.TimeUnit#MILLISECONDS

The following examples show how to use java.util.concurrent.TimeUnit#MILLISECONDS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Client.java    From rpc-benchmark with Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode({ Mode.Throughput, Mode.AverageTime, Mode.SampleTime })
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Override
public boolean existUser() throws Exception {
	return super.existUser();
}
 
Example 2
Source File: AsyncChannelGroupUtil.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private static AsynchronousChannelGroup createAsynchronousChannelGroup() {
    // Need to do this with the right thread context class loader else the
    // first web app to call this will trigger a leak
    ClassLoader original = Thread.currentThread().getContextClassLoader();

    try {
        Thread.currentThread().setContextClassLoader(
                AsyncIOThreadFactory.class.getClassLoader());

        // These are the same settings as the default
        // AsynchronousChannelGroup
        int initialSize = Runtime.getRuntime().availableProcessors();
        ExecutorService executorService = new ThreadPoolExecutor(
                0,
                Integer.MAX_VALUE,
                Long.MAX_VALUE, TimeUnit.MILLISECONDS,
                new SynchronousQueue<Runnable>(),
                new AsyncIOThreadFactory());

        try {
            return AsynchronousChannelGroup.withCachedThreadPool(
                    executorService, initialSize);
        } catch (IOException e) {
            // No good reason for this to happen.
            throw new IllegalStateException(sm.getString("asyncChannelGroup.createFail"));
        }
    } finally {
        Thread.currentThread().setContextClassLoader(original);
    }
}
 
Example 3
Source File: JmxMetricsReporter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private Builder(MetricRegistry registry) {
  this.registry = registry;
  this.rateUnit = TimeUnit.SECONDS;
  this.durationUnit = TimeUnit.MILLISECONDS;
  this.domain = "metrics";
  this.objectNameFactory = new DefaultObjectNameFactory();
}
 
Example 4
Source File: TestSystemMilliTimer.java    From kieker with Apache License 2.0 5 votes vote down vote up
/**
 * This method tests the timer with milliseconds as used time unit.
 */
@Test
public final void testMilliseconds() { // NOPMD (assert in superclass)
	final Configuration configuration = ConfigurationFactory.createDefaultConfiguration();
	configuration.setProperty(SystemMilliTimer.CONFIG_UNIT, "2");
	final ITimeSource ts = new SystemMilliTimer(configuration);
	super.testTime(ts, TimeUnit.MILLISECONDS);
}
 
Example 5
Source File: Client.java    From dubbo-benchmark with Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode({Mode.Throughput, Mode.AverageTime, Mode.SampleTime})
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Override
public User getUser() throws Exception {
    return super.getUser();
}
 
Example 6
Source File: ScalingPatternMatcherBenchmark.java    From stringbench with Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Warmup(iterations = 5, time=1)
@Measurement(iterations = 5, time=1)
@Fork(1)
public void benchmarkFindInString() {
	result = find(sample.getSample());
}
 
Example 7
Source File: CommonsPool2Benchmark.java    From lite-pool with Apache License 2.0 5 votes vote down vote up
@Benchmark
@Threads(2)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public void commons_pool2_02_thread() throws Exception  {
    TestObject object = pool.borrowObject();
    if (object != null) pool.returnObject(object);
}
 
Example 8
Source File: FutureBenchmark.java    From turbo-rpc with Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode({ Mode.Throughput })
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public Object completableFutureWithTimeout() {
	CompletableFuture<Integer> future = new CompletableFuture<>();

	future.orTimeout(1, TimeUnit.SECONDS);

	future.complete(Integer.valueOf(1));

	return future.join();
}
 
Example 9
Source File: DefaultConfigurationFactory.java    From candybar with Apache License 2.0 5 votes vote down vote up
/**
 * Creates default implementation of task executor
 */
public static Executor createExecutor(int threadPoolSize, int threadPriority,
                                      QueueProcessingType tasksProcessingType) {
    boolean lifo = tasksProcessingType == QueueProcessingType.LIFO;
    BlockingQueue<Runnable> taskQueue =
            lifo ? new LIFOLinkedBlockingDeque<Runnable>() : new LinkedBlockingQueue<Runnable>();
    return new ThreadPoolExecutor(threadPoolSize, threadPoolSize, 0L, TimeUnit.MILLISECONDS, taskQueue,
            createThreadFactory(threadPriority, "uil-pool-"));
}
 
Example 10
Source File: BuckEventOrdererTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testReordersEventsWithinSkewWindow() {
  BuckEvent first = createUniqueEvent(0, TimeUnit.MILLISECONDS, THREAD_ONE);
  BuckEvent second = createUniqueEvent(5, TimeUnit.MILLISECONDS, THREAD_ONE);

  try (BuckEventOrderer<BuckEvent> orderer =
      new BuckEventOrderer<>(addToSerializedEventsFunction, MAX_SKEW, TimeUnit.MILLISECONDS)) {
    orderer.add(second);
    orderer.add(first);
  }

  assertThat(serializedEvents, Matchers.contains(first, second));
}
 
Example 11
Source File: ConnectionOrderedChannelHandler.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public ConnectionOrderedChannelHandler(ChannelHandler handler, URL url) {
    super(handler, url);
    String threadName = url.getParameter(Constants.THREAD_NAME_KEY,Constants.DEFAULT_THREAD_NAME);
    connectionExecutor = new ThreadPoolExecutor(1, 1,
                                 0L, TimeUnit.MILLISECONDS,
                                 new LinkedBlockingQueue<Runnable>(url.getPositiveParameter(Constants.CONNECT_QUEUE_CAPACITY, Integer.MAX_VALUE)),
                                 new NamedThreadFactory(threadName, true),
                                 new AbortPolicyWithReport(threadName, url)
        );  // FIXME 没有地方释放connectionExecutor!
    queuewarninglimit = url.getParameter(Constants.CONNECT_QUEUE_WARNING_SIZE, Constants.DEFAULT_CONNECT_QUEUE_WARNING_SIZE);
}
 
Example 12
Source File: AsyncZuulServlet.java    From s2g-zuul with MIT License 5 votes vote down vote up
private void reNewThreadPool() {
    ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(coreSize.get(), maximumSize.get(), aliveTime.get(), TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>());
    ThreadPoolExecutor old = poolExecutorRef.getAndSet(poolExecutor);
    if (old != null) {
        shutdownPoolExecutor(old);
    }
}
 
Example 13
Source File: ResumableApiTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/** Verify that tryResume(TransctionId, long, TimeUnit) waits the full time and returns the expected
 *  value. 
 * 
 * @param txId The transaction ID to attempt to resume. 
 * @param timeValue A tryResume argument.
 * @param unit A tryResume argument.
 * @param expectedResult The expected result from tryResume.
 */
private void verifyTryResumeWaits(TransactionId txId, long timeValue, TimeUnit unit, boolean expectedResult) {
  Object[] tmp = tryResume(txId, timeValue, unit);
  boolean result = (Boolean)tmp[0];
  long duration = (Long)tmp[1];

  // verify the wait
  long expectedWaitMs = timeValue;
  if (unit == TimeUnit.SECONDS) {
    expectedWaitMs = timeValue * 1000;
  } else if (unit == TimeUnit.MICROSECONDS) {
    expectedWaitMs = timeValue / 1000;
  } else if (unit == TimeUnit.NANOSECONDS) {
    expectedWaitMs = timeValue / 1000000;
  } else if (unit == TimeUnit.MILLISECONDS){
    // already set
  } else {
    throw new TestException("Unknown TimeUnit " + unit);
  }
  if (duration < expectedWaitMs) {
    throw new TestException("Expected tryResume(" + txId + ", " + timeValue + ", " + unit + ") to wait for " +
        expectedWaitMs + "ms but it took " + duration + "ms");
  }
  if (result != expectedResult) {
    throw new TestException("Expected tryResume(" + txId + ", " + timeValue + ", " + unit + ") to return " +
        expectedResult + ", but it returned " + result);
  }
}
 
Example 14
Source File: BasicClient.java    From Bats with Apache License 2.0 4 votes vote down vote up
IdlePingHandler(long idleWaitInMillis) {
  super(0, idleWaitInMillis, 0, TimeUnit.MILLISECONDS);
}
 
Example 15
Source File: AbstractPoliciesBenchmark.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
@Benchmark
@Warmup(iterations = WARMUP_ITERATIONS, time = WARMUP_TIME, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = MEASUREMENT_ITERATIONS, time = MEASUREMENT_TIME, timeUnit = TimeUnit.MILLISECONDS)
public boolean benchmark_Scenario3Revoke16(final Scenario3Revoke16 scenario) {
    return runScenarioWithAlgorithm(scenario);
}
 
Example 16
Source File: AbstractPoliciesBenchmark.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
@Benchmark
@Warmup(iterations = WARMUP_ITERATIONS, time = WARMUP_TIME, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = MEASUREMENT_ITERATIONS, time = MEASUREMENT_TIME, timeUnit = TimeUnit.MILLISECONDS)
public boolean benchmark_Scenario2Nested1(final Scenario2Nested1 scenario) {
    return runScenarioWithAlgorithm(scenario);
}
 
Example 17
Source File: PhoebusApplication.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
private void startUI(final MementoTree memento, final JobMonitor monitor) throws Exception
{
    monitor.beginTask(Messages.MonitorTaskUi, 4);

    main_stage = new Stage();
    menuBar = createMenu(main_stage);
    toolbar = createToolbar();
    createTopResourcesMenu();

    DockStage.configureStage(main_stage);
    // Patch ID of main window
    // (in case we ever need to identify the main window)
    main_stage.getProperties().put(DockStage.KEY_ID, DockStage.ID_MAIN);

    // isToolbarVisible() and showToolbar() depend on layout.top -> VBox -> menu, toolbar
    final BorderPane layout = DockStage.getLayout(main_stage);
    layout.setTop(new VBox(menuBar, toolbar));
    layout.setBottom(StatusBar.getInstance());

    // Update items now that methods like isToolbarVisible()
    // can function since the scene has been populated
    show_toolbar.setSelected(isToolbarVisible());

    // Main stage may still be moved, resized, and restored apps are added.
    // --> Would be nice to _not_ show it, yet.
    // But restoreState will only find ID_MAIN when the window is visible
    // --> Do show it.
    main_stage.show();
    monitor.worked(1);

    // If there's nothing to restore from a previous instance,
    // start with welcome
    monitor.updateTaskName(Messages.MonitorTaskTabs);
    if (! restoreState(memento))
        new Welcome().create();
    monitor.worked(1);

    // Check command line parameters
    monitor.updateTaskName(Messages.MonitorTaskCmdl);
    handleParameters(getParameters().getRaw());
    monitor.worked(1);

    // In 'server' mode, handle parameters received from client instances
    ApplicationServer.setOnReceivedArgument(parameters ->
    {
        // Invoked by received arguments from the OS's file browser,
        // i.e. the file browser is currently in focus.
        // Assert that the phoebus window is visible
        Platform.runLater(() -> main_stage.toFront());
        handleClientParameters(parameters);
    });

    // Closing the primary window is like calling File/Exit.
    // When the primary window is the only open stage, that's OK.
    // If there are other stages still open,
    // closing them all might be unexpected to the user,
    // so prompt for confirmation.
    main_stage.setOnCloseRequest(event -> {
        if (closeMainStage(main_stage))
            stop();
        // Else: At least one tab in one stage didn't want to close
        event.consume();
    });

    DockPane.addListener(dock_pane_listener);
    DockPane.setActiveDockPane(DockStage.getDockPanes(main_stage).get(0));
    monitor.done();

    // Now that UI has loaded,
    // start the responsiveness check.
    // During startup, it would trigger
    // as the UI loads style sheets etc.
    if (Preferences.ui_monitor_period > 0)
        freezeup_check = new ResponsivenessMonitor(3 * Preferences.ui_monitor_period,
                                                   Preferences.ui_monitor_period, TimeUnit.MILLISECONDS);
}
 
Example 18
Source File: Custom.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
CustomTPE() {
    super(threadCount, threadCount,
          30, TimeUnit.MILLISECONDS,
          new ArrayBlockingQueue<Runnable>(2*threadCount));
}
 
Example 19
Source File: ThreadPoolMonitorTest.java    From spectator with Apache License 2.0 4 votes vote down vote up
LatchedThreadPoolExecutor(final CountDownLatch completed) {
  super(3, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
  this.completed = completed;
}
 
Example 20
Source File: PeriodicTrigger.java    From audit4j-core with Apache License 2.0 2 votes vote down vote up
/**
 * Create a trigger with the given period and time unit. The time unit will
 * apply not only to the period but also to any 'initialDelay' value, if
 * configured on this Trigger later via {@link #setInitialDelay(long)}.
 *
 * @param period the period
 * @param timeUnit the time unit
 */
public PeriodicTrigger(long period, TimeUnit timeUnit) {
    //Assert.isTrue(period >= 0, "period must not be negative");
    this.timeUnit = timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS;
    this.period = this.timeUnit.toMillis(period);
}