Example usage for java.util.concurrent TimeUnit MILLISECONDS

List of usage examples for java.util.concurrent TimeUnit MILLISECONDS

Introduction

In this page you can find the example usage for java.util.concurrent TimeUnit MILLISECONDS.

Prototype

TimeUnit MILLISECONDS

To view the source code for java.util.concurrent TimeUnit MILLISECONDS.

Click Source Link

Document

Time unit representing one thousandth of a second.

Usage

From source file:com.verigreen.common.concurrency.timeboundedexecuter.TimeBoundedExecuter.java

/**
 * Executes the given actions in parallel, returns when all actions are completed or until the
 * given timeout elapses.//from  w  ww. ja v a 2s  . c o  m
 * 
 * @return List with actions results
 */
public void perform(List<Action<Void>> actions, long timeBoundInMillis) {

    List<TimeBoundedThread<Void>> tasks = createTimeBoundedThreads(actions);
    try {
        _executerService.invokeAll(tasks, timeBoundInMillis, TimeUnit.MILLISECONDS);
    } catch (Throwable thrown) {
        _logger.error(String.format("Got unexpected error while performing the following actions: %s", actions),
                thrown);
    }
}

From source file:com.dbay.apns4j.impl.ApnsServiceImpl.java

private ApnsServiceImpl(ApnsConfig config, ErrorProcessHandler errorProcessHandler)
        throws UnrecoverableKeyException, KeyManagementException, KeyStoreException, NoSuchAlgorithmException,
        CertificateException, CertificateExpiredException, IOException {
    this.name = config.getName();
    int poolSize = config.getPoolSize();
    // this.service = Executors.newFixedThreadPool(poolSize);
    this.service = new ThreadPoolExecutor(poolSize, poolSize, 0L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>(queueSize));

    SocketFactory factory = ApnsTools.createSocketFactory(config.getKeyStore(), config.getPassword(),
            KEYSTORE_TYPE, ALGORITHM, PROTOCOL);
    this.connPool = ApnsConnectionPool.newConnPool(config, factory, errorProcessHandler);
    this.feedbackConn = new ApnsFeedbackConnectionImpl(config, factory);
}

From source file:at.ac.univie.isc.asio.tool.Timeout.java

/**
 * Convert a text representation as created by {@link #toString()} into a timeout instance.
 *
 * @param text a string representing a timeout value
 * @return the parsed timeout instance/* w  w w .  j a va2s . c o  m*/
 * @throws IllegalArgumentException if the given string is not a representation of a timeout
 */
@JsonCreator
public static Timeout fromString(final String text) throws IllegalArgumentException {
    requireNonNull(text, "cannot parse <" + text + "> as timeout (null)");
    if ("undefined".equals(text)) {
        return Timeout.undefined();
    }
    if (text.endsWith("ms")) {
        final Long value = Long.valueOf(text.substring(0, text.length() - 2));
        return Timeout.from(value, TimeUnit.MILLISECONDS);
    }
    throw new IllegalArgumentException("cannot parse <" + text + "> as timeout (invalid format)");
}

From source file:com.bfd.harpc.heartbeat.HeartBeatManager.java

/**
 * ?heartbeat//from ww  w.  j  a  v a 2s  .  co  m
 * <p>
 */
public void startHeatbeatTimer() {
    stopHeartbeatTimer();
    if (heartbeat > 0) {
        heatbeatTimer = scheduled.scheduleWithFixedDelay(
                new HeartBeatTask<T>(dynamicHostSet, times, interval, heartbeatTimeout, pool), heartbeat,
                heartbeat, TimeUnit.MILLISECONDS);
    }
}

From source file:com.heliosapm.opentsdb.AnnotationBuilder.java

/**
 * Creates a new AnnotationBuilder with a start time of current
 *//*from   w  ww.  j a v a 2s  . c  om*/
public AnnotationBuilder() {
    this((int) TimeUnit.SECONDS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS));
}

From source file:com.github.jarlakxen.embedphantomjs.PhantomJSExecutorTest.java

@Test
public void test_FileExecutor_FromString_Timeout() throws InterruptedException, ExecutionException {
    PhantomJSFileExecutor ex = new PhantomJSFileExecutor(PhantomJSReference.create().build(),
            new ExecutionTimeout(100, TimeUnit.MILLISECONDS));
    ListenableFuture<String> result = ex.execute("while(true){};");
    Thread.sleep(200);//  w ww . j  a  v a  2s .  co  m
    assertEquals(true, result.isCancelled());
}

From source file:org.zalando.zmon.actuator.backend.ZmonRestBackendMetricsTest.java

@Before
public void setUp() {
    ConsoleReporter reporter = ConsoleReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS).build();
    reporter.start(2, TimeUnit.SECONDS);
    expectDeleteCall();//w  w  w  .ja va 2  s .c  o m
}

From source file:co.marcin.novaguilds.manager.PlayerManager.java

public void save() {
    long startTime = System.nanoTime();
    int count = getResourceManager().save(getPlayers());
    LoggerUtils.info("Players data saved in "
            + TimeUnit.MILLISECONDS.convert((System.nanoTime() - startTime), TimeUnit.NANOSECONDS) / 1000.0
            + "s (" + count + " players)");

    startTime = System.nanoTime();
    count = getResourceManager().executeRemoval();
    LoggerUtils.info("Players removed in "
            + TimeUnit.MILLISECONDS.convert((System.nanoTime() - startTime), TimeUnit.NANOSECONDS) / 1000.0
            + "s (" + count + " players)");
}

From source file:com.espertech.esper.util.ManagedReadWriteLock.java

/**
 * Try write lock with timeout, returning an indicator whether the lock was acquired or not.
 * @param msec number of milliseconds to wait for lock
 * @return indicator whether the lock could be acquired or not
 *///from  w  w w .j av  a2 s. c o m
public boolean tryWriteLock(long msec) {
    if (ThreadLogUtil.ENABLED_TRACE) {
        ThreadLogUtil.traceLock(TRY_TEXT + " write " + name, lock);
    }

    boolean result = false;
    try {
        result = lock.writeLock().tryLock(msec, TimeUnit.MILLISECONDS);
    } catch (InterruptedException ex) {
        log.warn("Lock wait interupted");
    }

    if (ThreadLogUtil.ENABLED_TRACE) {
        ThreadLogUtil.traceLock(TRY_TEXT + " write " + name + " : " + result, lock);
    }

    return result;
}

From source file:com.twitter.distributedlog.config.TestConfigurationSubscription.java

@Test(timeout = 60000)
public void testReloadConfiguration() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
    ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new DistributedLogConfiguration());
    DeterministicScheduler executorService = new DeterministicScheduler();
    List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
    ConfigurationSubscription confSub = new ConfigurationSubscription(conf, fileConfigBuilders, executorService,
            100, TimeUnit.MILLISECONDS);
    final AtomicReference<ConcurrentBaseConfiguration> confHolder = new AtomicReference<>();
    confSub.registerListener(new com.twitter.distributedlog.config.ConfigurationListener() {
        @Override/*w w  w .  j a v a2  s . c  o  m*/
        public void onReload(ConcurrentBaseConfiguration conf) {
            confHolder.set(conf);
        }
    });
    assertEquals(null, conf.getProperty("prop1"));

    // add
    writer.setProperty("prop1", "1");
    writer.save();
    // ensure the file change reloading event can be triggered
    ensureConfigReloaded();
    // reload the config
    confSub.reload();
    assertNotNull(confHolder.get());
    assertTrue(conf == confHolder.get());
    assertEquals("1", conf.getProperty("prop1"));
}