Example usage for java.util.concurrent TimeUnit SECONDS

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

Introduction

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

Prototype

TimeUnit SECONDS

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

Click Source Link

Document

Time unit representing one second.

Usage

From source file:com.ms.commons.fasttext.FasttextService.java

private static void createThreadPool() {
    Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(new Runnable() {

        public void run() {
            reload();//from w w  w .j  a v a  2s . co m
        }
    }, DELAY_TIME, DELAY_TIME, TimeUnit.SECONDS);
}

From source file:com.joyent.manta.client.MetricReporterSupplier.java

/**
 * Constructing an instance of this class prepares the desired metric reporter based on the supplied configuration.
 *
 * @param metricConfig details about the type of reporter to construct and any necessary additional parameters
 *///from   w  w w  .j a v  a  2s  . c  om
MetricReporterSupplier(final MantaClientMetricConfiguration metricConfig) {
    notNull(metricConfig);

    switch (metricConfig.getReporterMode()) {
    case JMX:
        final JmxReporter jmxReporter = buildJmxReporter(metricConfig);
        jmxReporter.start();
        this.reporter = jmxReporter;
        break;
    case SLF4J:
        final Slf4jReporter slf4jReporter = buildSlf4jReporter(metricConfig);
        slf4jReporter.start(metricConfig.getPeriodicReporterOutputInterval(), TimeUnit.SECONDS);
        this.reporter = slf4jReporter;
        break;
    case DISABLED:
    default:
        this.reporter = null;
    }
}

From source file:org.apache.sling.hapi.client.test.util.HttpServerRule.java

@Override
protected void after() {
    server.shutdown(-1, TimeUnit.SECONDS);
}

From source file:com.jsmartframework.web.config.CachePattern.java

public String getExpiresHeader() {
    if (maxAge == 0) {
        return DEFAULT_EXPIRES;
    }//ww  w.  j  av  a2  s .c o  m
    return String.valueOf(TimeUnit.SECONDS.toMillis(maxAge));
}

From source file:org.italiangrid.storm.webdav.authz.vomap.DefaultVOMapDetailsService.java

private void scheduleRefresh() {

    Runnable refreshTask = new Runnable() {

        @Override// w w  w  . j  a va 2 s .c  om
        public void run() {

            refresh();

        }
    };

    scheduler.scheduleWithFixedDelay(refreshTask, refreshPeriodInSeconds, refreshPeriodInSeconds,
            TimeUnit.SECONDS);

}

From source file:com.github.restdriver.clientdriver.integration.WhenCompletedTest.java

/**
 * This test might seem a touch weird so is worthy of comment:
 * /*ww w. j a  v a2 s .  c o  m*/
 * It sets up a thread that fires after 500 milliseconds and adds an expectation to receive that request within
 * 1 second. Once the request has been sent the 'done' boolean is set to true. We add a completion listener that
 * asserts that done is true.
 * 
 * If we were to write this normally (where the assertion is simply at the end of the method) it would fail.
 */
@Test
public void assertionWaitsUntilClientDriverIsFinished() throws Exception {

    clientDriver.addExpectation(onRequestTo("/hello"), giveEmptyResponse().within(1, TimeUnit.SECONDS));

    clientDriver.whenCompleted(new ClientDriverCompletedListener() {
        @Override
        public void hasCompleted() {
            assertThat(done, is(true));
        }
    });

    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            schnoozeFor(500);
            hitThat(clientDriver.getBaseUrl() + "/hello");
            done = true;
        }
    });
    thread.setDaemon(true);
    thread.start();

}

From source file:com.dcits.govsbu.southernbase.baseproject2.helper.AuthorityHelper.java

@PostConstruct
public void init() {
    logger.debug("? " + loginTimeoutSecs);
    // CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(loginTimeoutSecs, TimeUnit.SECONDS).build();
    loginUsers = CacheBuilder.newBuilder().maximumSize(1000)
            .expireAfterAccess(loginTimeoutSecs, TimeUnit.SECONDS).build();
}

From source file:com.xyxy.platform.examples.showcase.demos.schedule.JdkTimerJob.java

@PostConstruct
public void start() throws Exception {
    Validate.isTrue(period > 0);/* ww w.  j a  va 2 s  .co  m*/

    // ?schedule, Spring TaskUtilsLOG_AND_SUPPRESS_ERROR_HANDLER?
    Runnable task = TaskUtils.decorateTaskWithErrorHandler(this, null, true);

    // ?SechdulerExecutor,guavaThreadFactoryBuilder???
    scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(
            new ThreadFactoryBuilder().setNameFormat("JdkTimerJob-%1$d").build());

    // scheduleAtFixedRatefixRate() ?.
    // scheduleAtFixedDelay() ???.
    scheduledExecutorService.scheduleAtFixedRate(task, initialDelay, period, TimeUnit.SECONDS);
}

From source file:net.jodah.failsafe.internal.actions.DelayedForAction.java

@Override
protected boolean shouldRepeat(ActionContext<R> context) throws InterruptedException {
    if (currentCount == 0) { // should execute only once
        logger.debug("FailsafeController({}): delaying {} seconds", controller, delay);
        Thread.sleep(TimeUnit.SECONDS.toMillis(delay));
        return true;
    }//from   ww w .  j  a va 2s.  c o  m
    return false;
}

From source file:com.netflix.curator.framework.recipes.queue.TestDistributedDelayQueue.java

@Test
public void testLateAddition() throws Exception {
    Timing timing = new Timing();
    DistributedDelayQueue<Long> queue = null;
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(),
            timing.connection(), new RetryOneTime(1));
    client.start();/*from  w  w  w .j av  a 2 s  .  c  o  m*/
    try {
        BlockingQueueConsumer<Long> consumer = new BlockingQueueConsumer<Long>(
                Mockito.mock(ConnectionStateListener.class));
        queue = QueueBuilder.builder(client, consumer, new LongSerializer(), "/test").buildDelayQueue();
        queue.start();

        queue.put(1L, System.currentTimeMillis() + Integer.MAX_VALUE); // never come out
        Long value = consumer.take(1, TimeUnit.SECONDS);
        Assert.assertNull(value);

        queue.put(2L, System.currentTimeMillis());
        value = consumer.take(timing.seconds(), TimeUnit.SECONDS);
        Assert.assertEquals(value, Long.valueOf(2));

        value = consumer.take(1, TimeUnit.SECONDS);
        Assert.assertNull(value);
    } finally {
        IOUtils.closeQuietly(queue);
        IOUtils.closeQuietly(client);
    }
}