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.bia.yahoomailjava.YahooMailService.java

/**
 *
 * @param toAddress mandatory//from   w w  w.ja v  a 2  s  .  c  om
 * @param subject mandatory
 * @param body optional
 * @return true email send, false invalid input
 */
public boolean sendEmail(String toAddress, String subject, String body) {
    if (!isValidEmail(toAddress) || !isValidSubject(subject)) {
        return false;
    }

    String[] to = { toAddress };
    // Aysnc send email
    Runnable emailServiceAsync = new EmailServiceAsync(to, subject, body);
    executor.schedule(emailServiceAsync, 1, TimeUnit.MILLISECONDS);

    return true;
}

From source file:com.alibaba.doris.admin.service.failover.node.check.NodeCheckService.java

/**
 * ??// ww w .  j a v  a2  s . c  o  m
 * 
 * @param timeout ???0?
 * @see java.util.concurrent.ExecutorService#invokeAll(java.util.Collection)
 */
public List<NodeCheckResult> invokeAll(List<? extends NodeCheckTask> tasks, long timeout) {
    List<NodeCheckResult> nodes = new ArrayList<NodeCheckResult>(tasks.size());
    try {
        List<Future<NodeCheckResult>> futures = null;
        if (timeout < 0) {
            futures = executorService.invokeAll(tasks, DEFAULT_TASK_TIMEOUT * tasks.size(),
                    TimeUnit.MILLISECONDS);
        } else {
            futures = executorService.invokeAll(tasks, timeout, TimeUnit.MILLISECONDS);
        }
        for (Future<NodeCheckResult> future : futures) {
            try {
                nodes.add(future.get());
            } catch (ExecutionException e) {
                log.error("failed to check node, skip and continue.", e);
            }
        }
    } catch (InterruptedException e) {
        log.error("failed to check node, skip and continue.", e);
    }
    return nodes;
}

From source file:com.gemstone.gemfire.test.junit.rules.serializable.SerializableTimeoutTest.java

@Test
public void fieldsCanBeRead() throws Exception {
    long timeout = 1000;
    TimeUnit timeUnit = TimeUnit.MILLISECONDS;
    boolean lookingForStuckThread = false;

    SerializableTimeout instance = SerializableTimeout.builder().withTimeout(timeout, timeUnit)
            .withLookingForStuckThread(lookingForStuckThread).build();

    assertThat(readField(Timeout.class, instance, FIELD_TIMEOUT)).isEqualTo(timeout);
    assertThat(readField(Timeout.class, instance, FIELD_TIME_UNIT)).isEqualTo(timeUnit);
    assertThat(readField(Timeout.class, instance, FIELD_LOOK_FOR_STUCK_THREAD))
            .isEqualTo(lookingForStuckThread);
}

From source file:example.pki.VaultPkiConfiguration.java

/**
 * Obtain SSL certificate (cached/request new certificate) with startup locking.
 *
 * @param vaultProperties/* w  w  w .j  av  a  2  s  .  c o m*/
 * @param vaultOperations
 * @param pkiProperties
 * @param serverProperties
 * @param synchronizationProvider
 * @return
 * @throws Exception
 */
@Bean
@ConditionalOnProperty(prefix = "server.ssl", name = "enabled", havingValue = "true")
public static SslCertificateEmbeddedServletContainerCustomizer sslCertificateRequestingPostProcessor(
        VaultProperties vaultProperties, VaultOperations vaultOperations, VaultPkiProperties pkiProperties,
        ServerProperties serverProperties, SynchronizationProvider synchronizationProvider) throws Exception {

    Lock lock = synchronizationProvider.getLock();

    CertificateBundle certificateBundle = CertificateUtil.findValidCertificate(vaultProperties, vaultOperations,
            pkiProperties);

    if (certificateBundle != null) {
        return createCustomizer(serverProperties, certificateBundle);
    }

    boolean locked = lock.tryLock(pkiProperties.getStartupLockTimeout(), TimeUnit.MILLISECONDS);

    if (!locked) {
        throw new IllegalStateException(String.format("Could not obtain SSL synchronization lock within %d %s",
                pkiProperties.getStartupLockTimeout(), TimeUnit.MILLISECONDS));
    }

    try {
        certificateBundle = CertificateUtil.getOrRequestCertificate(vaultProperties, vaultOperations,
                pkiProperties);

        return createCustomizer(serverProperties, certificateBundle);
    } finally {
        lock.unlock();
    }

}

From source file:com.datastax.example.MapSizeTest.java

public void test1() {

    final CsvReporter reporter = CsvReporter.forRegistry(metrics).formatFor(Locale.US)
            .convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS)
            .build(new File("/Users/patrick/projects/"));

    logger.info("Beginning MapSizeTest:Test1");

    int key = 0;//from  w  ww .  j a  va 2 s.co m

    reporter.start(1, TimeUnit.SECONDS);

    //Insert 100 items at a time, up to 64k items
    for (int i = 0; i < 640; i++) {

        for (int j = 0; j < 100; j++) {

            final Timer.Context context = requestLatency.time();
            session.execute("update maptest set intMap = {" + key + ":" + key + "} where id = 0");
            context.stop();

            key++;
        }
    }

    logger.info("Completed MapSizeTest:Test1");
}

From source file:ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory.java

public synchronized HttpClient getNativeHttpClient() {
    if (myHttpClient == null) {

        PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000,
                TimeUnit.MILLISECONDS);
        connectionManager.setMaxTotal(getPoolMaxTotal());
        connectionManager.setDefaultMaxPerRoute(getPoolMaxPerRoute());

        // @formatter:off
        RequestConfig defaultRequestConfig = RequestConfig.custom().setSocketTimeout(getSocketTimeout())
                .setConnectTimeout(getConnectTimeout())
                .setConnectionRequestTimeout(getConnectionRequestTimeout()).setStaleConnectionCheckEnabled(true)
                .setProxy(myProxy).build();

        HttpClientBuilder builder = HttpClients.custom().setConnectionManager(connectionManager)
                .setDefaultRequestConfig(defaultRequestConfig).disableCookieManagement();

        if (myProxy != null && StringUtils.isNotBlank(getProxyUsername())
                && StringUtils.isNotBlank(getProxyPassword())) {
            CredentialsProvider credsProvider = new BasicCredentialsProvider();
            credsProvider.setCredentials(new AuthScope(myProxy.getHostName(), myProxy.getPort()),
                    new UsernamePasswordCredentials(getProxyUsername(), getProxyPassword()));
            builder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
            builder.setDefaultCredentialsProvider(credsProvider);
        }/*ww w .  j a  va  2s.c om*/

        myHttpClient = builder.build();
        // @formatter:on

    }

    return myHttpClient;
}

From source file:com.microsoft.office.integration.test.FoldersAsyncTestCase.java

public void testRead() {
    prepareFolder();//from  w w  w  .j ava2 s  .  co m
    counter = new CountDownLatch(1);
    Futures.addCallback(Me.flushAsync(), new FutureCallback<Void>() {
        public void onFailure(Throwable t) {
            reportError(t);
            counter.countDown();
        }

        public void onSuccess(Void result) {
            try {
                FoldersAsyncTestCase.this.readAndCheck();
                FoldersAsyncTestCase.this.removeFolder();
            } catch (Throwable t) {
                reportError(t);
            }

            counter.countDown();
        }
    });

    try {
        if (!counter.await(60000, TimeUnit.MILLISECONDS)) {
            fail("testRead() timed out");
        }
    } catch (InterruptedException e) {
        fail("testRead() has been interrupted");
    }
}

From source file:com.adaptris.jdbc.StoredProcedure.java

public JdbcResult execute() throws CoreException {

    try {//from www.j a v a2 s.c o m
        String sqlStatement = getStatementCreator().createCall(getName(), getParameters().size());
        log.trace("Generated SQL Statement [{}]", sqlStatement);
        CallableStatement statement = getConnection().prepareCall(sqlStatement);
        if (timeout > 0) {
            statement.setQueryTimeout((int) TimeUnit.MILLISECONDS.toSeconds(this.getTimeout()));
        }
        applyInParameters(statement);

        JdbcResult results = statementExecutor.executeCallableStatement(statement);

        translateResultSet(getAdaptrisMessage(), results);

        applyOutParameters(statement);
        results.setParameters(getParameters());

        return results;

    } catch (SQLException e) {
        throw new CoreException(e);
    }
}

From source file:com.unknown.pkg.TokenTestApplicationIT.java

@Before
public void localSetup() {
    ConsoleReporter reporter = ConsoleReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS).build();
    reporter.start(2, TimeUnit.SECONDS);
}

From source file:com.microsoft.office.integration.test.EventsAsyncTestCase.java

@Override
protected void setUp() throws Exception {
    super.setUp();
    final ICalendars cals = Me.getCalendars();
    final CountDownLatch cdl = new CountDownLatch(1);
    // an empty iterator will be returned for any entity set unless you call fetch()
    Futures.addCallback(cals.fetchAsync(), new FutureCallback<Void>() {
        public void onFailure(Throwable t) {
            cdl.countDown();//from   w w  w .  j  a  v a 2 s. c o  m
        }

        public void onSuccess(Void result) {
            Iterator<ICalendar> iterator = cals.iterator();
            if (iterator.hasNext()) {
                calendar = iterator.next();
            }
            cdl.countDown();
        }
    });

    cdl.await(60000, TimeUnit.MILLISECONDS);
    if (calendar == null) {
        fail("No calendar found");
    }
}