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:org.freewheelschedule.freewheel.remoteworker.RunnerThread.java

@Override
public void run() {
    log.info("Worker thread is running.");

    Execution commandLine = null;/*from w ww.  j  a  v a 2  s .c  om*/

    do {
        try {
            log.debug("Waiting for command to come from listener.");
            JobInitiationMessage command = jobQueue.poll(timeout, TimeUnit.MILLISECONDS);
            if (command != null) {
                log.info("Command received: " + command);
                if (command.getJobType().equals(JobType.COMMAND)) {
                    commandLine = new CommandLineExecution();
                    commandLine.setCommand(command);
                    commandLine.setRemotePort(remotePort);
                }
                threadPool.submit(commandLine);
            } else {
                log.info("Timeout waiting for jobQueue");
            }
        } catch (InterruptedException e) {
            log.error("RunnerThread sleep was interrupted", e);
        }
    } while (continueWaiting);

}

From source file:com.jive.myco.seyren.core.service.schedule.CheckScheduler.java

@PreDestroy
public void preDestroy() throws InterruptedException {
    executor.shutdown();
    executor.awaitTermination(500, TimeUnit.MILLISECONDS);
}

From source file:com.newlandframework.avatarmq.core.MessageCache.java

public boolean hold(long timeout) {
    try {//from   w  w w .j  a  va 2 s  . c  om
        return semaphore.tryAcquire(timeout, TimeUnit.MILLISECONDS);
    } catch (InterruptedException ex) {
        Logger.getLogger(MessageCache.class.getName()).log(Level.SEVERE, null, ex);
        return false;
    }
}

From source file:com.guang.eunormia.common.dislock.ZKClient.java

public void init() throws Exception {
    connectedSignal = new CountDownLatch(1);
    zookeeper = new ZooKeeper(zkAddress, timeout, this);
    if (connectedSignal.await(6000, TimeUnit.MILLISECONDS)) {
        logger.warn("- the conect to zookeeper server success ...");
    } else {/*w  ww .  ja v  a 2 s. c o  m*/
        logger.error("- try to establish connection to zookeeper timeout ...");
        throw new Exception("- try to establish connection to zookeeper timeout ...");
    }
}

From source file:com.walmart.gatling.MonitoringConfiguration.java

@Bean
public GraphiteReporter graphiteReporter(Graphite graphite, MetricRegistry registry,
        @Value("${graphite.prefix}") String prefix,
        @Value("${graphite.frequency-in-seconds}") long frequencyInSeconds) {
    GraphiteReporter reporter = GraphiteReporter.forRegistry(registry)
            .prefixedWith(prefix + "." + HostUtils.lookupHost()).convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).build(graphite);
    reporter.start(frequencyInSeconds, TimeUnit.SECONDS);

    return reporter;
}

From source file:com.orange.retrytest.OkHttpStack.java

@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    OkHttpClient.Builder clientBuilder = client.newBuilder();
    int timeoutMs = request.getTimeoutMs();
    clientBuilder.connectTimeout(timeoutMs, TimeUnit.MILLISECONDS);
    clientBuilder.readTimeout(timeoutMs, TimeUnit.MILLISECONDS);
    clientBuilder.writeTimeout(timeoutMs, TimeUnit.MILLISECONDS);
    OkHttpClient client = clientBuilder.build();

    okhttp3.Request.Builder requestBuilder = new okhttp3.Request.Builder();
    requestBuilder.url(request.getUrl());

    setHeaders(requestBuilder, request, additionalHeaders);
    setConnectionParameters(requestBuilder, request);

    okhttp3.Request okHttpRequest = requestBuilder.build();
    Call okHttpCall = client.newCall(okHttpRequest);
    Response okHttpResponse = okHttpCall.execute();

    StatusLine responseStatus = new BasicStatusLine(parseProtocol(okHttpResponse.protocol()),
            okHttpResponse.code(), okHttpResponse.message());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    response.setEntity(getEntity(okHttpResponse));

    Headers responseHeaders = okHttpResponse.headers();
    for (int i = 0, len = responseHeaders.size(); i < len; i++) {
        response.addHeader(new BasicHeader(responseHeaders.name(i), responseHeaders.value(i)));
    }/*from  w  w  w  .j a va2s  .c om*/

    return response;
}

From source file:org.eclipse.mylyn.internal.commons.repositories.http.core.IdleConnectionMonitorThread.java

@Override
public void run() {
    try {//w  ww . j ava 2 s. co m
        while (!shutdown) {
            for (ClientConnectionManager connectionManager : connectionManagers) {
                connectionManager.closeExpiredConnections();
                if (timeout > 0) {
                    connectionManager.closeIdleConnections(timeout, TimeUnit.MILLISECONDS);
                }
            }

            synchronized (this) {
                wait(pollingInterval);
            }
        }
    } catch (InterruptedException e) {
        // shutdown
    }
}

From source file:com.krawler.notify.email.PausableEmailSender.java

@Override
public void send(Message msg) throws NotificationException {
    pauseLock.lock();/* w w  w .j  a  va2s. co m*/
    try {
        if (pauseSize > 0 && pauseCounter == pauseSize) {
            paused = true;
            logger.debug("Wait Start");
            unpaused.await(pauseTime, TimeUnit.MILLISECONDS);
            pauseCounter = 0;
            logger.debug("Wait End");
        }
    } catch (InterruptedException ie) {
        logger.warn("Pause Interrupted", ie);
        Thread.currentThread().interrupt();
    } finally {
        paused = false;
        pauseCounter++;
        pauseLock.unlock();
    }

    super.send(msg);
}

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

public void test1() {

    Random rnd = new Random();

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

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

    reporter.start(1, TimeUnit.SECONDS);

    //Insert 10000
    for (int i = 0; i < 1000000; i++) {

        String firstName = RandomStringUtils.randomAlphabetic(10);
        String lastName = RandomStringUtils.randomAlphabetic(10);
        String street = RandomStringUtils.randomAlphabetic(8);
        int post_code = rnd.nextInt(99999);
        int phone = rnd.nextInt(99999999);

        final Timer.Context context = test1.time();

        session.execute("insert into users (id, firstname, lastname, street, post_code, phone) VALUES (" + i
                + ", '" + firstName + "', '" + lastName + "', '" + street + "', " + post_code + ", " + phone
                + ");");

        context.stop();//ww  w . j  ava 2  s .c  o  m

    }

    logger.info("Completed PreparedVsNonPreparedStatement:Test1");

}

From source file:com.socialize.net.IdleConnectionMonitorThread.java

@Override
public void run() {
    try {//  w w w . ja  v a  2s . c om
        while (!shutdown) {
            synchronized (this) {
                wait(timeout);
                // Close expired connections
                connMgr.closeExpiredConnections();
                // Optionally, close connections
                // that have been idle longer than [timeout] milliseconds
                connMgr.closeIdleConnections(timeout, TimeUnit.MILLISECONDS);
            }
        }
    } catch (InterruptedException ex) {
        // terminate
    }
}