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.addthis.codec.utils.ExecutorServiceBuilder.java

@JsonCreator
public ExecutorServiceBuilder(@JsonProperty("thread-factory") ThreadFactory threadFactory,
        @JsonProperty("core-threads") int coreThreads, @JsonProperty("max-threads") int maxThreads,
        @JsonProperty("keep-alive") @Time(TimeUnit.MILLISECONDS) int keepAlive,
        @JsonProperty("queue-size") int queueSize, @JsonProperty("queue-gauge-class") Class<?> gaugeClass,
        @JsonProperty("queue-gauge-name") String gaugeName,
        @JsonProperty("shutdown-hook") boolean shutdownHook) {
    this.threadFactory = threadFactory;
    this.coreThreads = coreThreads;
    this.maxThreads = maxThreads;
    this.keepAlive = keepAlive;
    this.queue = new LinkedBlockingQueue<>(queueSize);
    if ((gaugeClass != null) && (gaugeName != null)) {
        Metrics.newGauge(gaugeClass, gaugeName, new SizeGauge(queue));
    }// www  .  j  a  v  a  2  s .  c  o  m
    this.shutdownHook = shutdownHook;
}

From source file:com.frostwire.search.VuzeMagnetDownloader.java

public byte[] download(String magnet, int timeout) {

    CountDownLatch signal = new CountDownLatch(1);

    String saveDir = SharingSettings.TORRENTS_DIR_SETTING.getValue().getAbsolutePath();

    TorrentDownloaderListener listener = new TorrentDownloaderListener(signal);

    TorrentDownloader td = TorrentDownloaderFactory.create(listener, magnet, null, saveDir);

    td.start();/*from  w  w  w . j  ava2  s. c  o m*/

    try {
        signal.await(timeout, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        // ignore
    }

    if (listener.getData() == null) {
        td.cancel();
    }

    return listener.getData();
}

From source file:com.newlandframework.test.RpcParallelTest.java

public static void addTask(AddCalculate calc, int parallel) throws InterruptedException {
    RpcParallelTest.parallelAddCalcTask(calc, parallel);
    TimeUnit.MILLISECONDS.sleep(30);
}

From source file:com.jayway.restassured.module.mockmvc.AsyncTest.java

@Test
public void can_supply_string_as_body_for_async_post_with_config_in_given() {
    given().config(newConfig().asyncConfig(withTimeout(10, TimeUnit.MILLISECONDS))).body("a string").when()
            .async().post("/stringBody").then().body(equalTo("a string"));
}

From source file:io.undertow.server.handlers.ChunkedRequestNotConsumedTestCase.java

@BeforeClass
public static void setup() {
    DefaultServer.setRootHandler(new HttpHandler() {
        @Override/*from  w  ww .  j  a va 2  s  . c o  m*/
        public void handleRequest(final HttpServerExchange exchange) throws InterruptedException {
            exchange.setResponseContentLength("message".length());
            exchange.getResponseSender().send("message", new IoCallback() {
                @Override
                public void onComplete(HttpServerExchange exchange, Sender sender) {
                    exchange.dispatch(SameThreadExecutor.INSTANCE, new Runnable() {
                        @Override
                        public void run() {
                            exchange.getIoThread().executeAfter(new Runnable() {
                                @Override
                                public void run() {
                                    exchange.endExchange();
                                }
                            }, 300, TimeUnit.MILLISECONDS);
                        }
                    });
                }

                @Override
                public void onException(HttpServerExchange exchange, Sender sender, IOException exception) {
                    exchange.endExchange();
                }
            });
        }
    });
}

From source file:com.googlecode.ehcache.annotations.integration.PartialCacheKeyTest.java

@Test
public void testPartialKeyGeneration() {
    assertEquals(0, this.partialCacheKeyTestInterface.cacheableMethodOneCount());

    this.partialCacheKeyTestInterface.cacheableMethodOne("a", 1, 12, TimeUnit.MILLISECONDS);
    assertEquals(1, this.partialCacheKeyTestInterface.cacheableMethodOneCount());

    this.partialCacheKeyTestInterface.cacheableMethodOne("a", 1, 12, TimeUnit.MILLISECONDS);
    assertEquals(1, this.partialCacheKeyTestInterface.cacheableMethodOneCount());

    this.partialCacheKeyTestInterface.cacheableMethodOne("a", 1, 12, null);
    assertEquals(1, this.partialCacheKeyTestInterface.cacheableMethodOneCount());

    this.partialCacheKeyTestInterface.cacheableMethodOne("a", 1, 0, TimeUnit.MILLISECONDS);
    assertEquals(2, this.partialCacheKeyTestInterface.cacheableMethodOneCount());
}

From source file:com.mmj.app.common.notify.NotifyService.java

@PostConstruct
void init() {//ww w  . j a v a 2  s .c  o  m
    Executors.newScheduledThreadPool(corePoolSize).scheduleAtFixedRate(new Runnable() {

        @Override
        public void run() {
            try {
                // logger.debug("poll the queue...");
                fireEvent();
            } catch (Throwable e) {
                logger.error(e.getMessage(), e);
            }
        }
    }, deplaySeconds, fixRate, TimeUnit.MILLISECONDS);
}

From source file:org.seasar.robot.client.http.HcConnectionMonitorTarget.java

@Override
public void expired() {
    try {//  w  w w . ja  v  a  2s  .  c  o  m
        // Close expired connections
        clientConnectionManager.closeExpiredConnections();
        // Close idle connections
        clientConnectionManager.closeIdleConnections(idleConnectionTimeout, TimeUnit.MILLISECONDS);
    } catch (final Exception e) {
        logger.warn("A connection monitoring exception occurs.", e);
    }
}

From source file:com.nesscomputing.jms.activemq.DiscoveryJmsUriInterceptor.java

@Inject
DiscoveryJmsUriInterceptor(ReadOnlyDiscoveryClient discoveryClient, DiscoveryJmsConfig config) {
    this.config = config;

    LOG.debug("Waiting for world change then registering discovery client %s", injectorId);
    // Ensure that we don't register a discovery client until it's had at least one world-change (or give up due to timeout)
    try {//  w  ww.jav  a2 s  .  c  o m
        discoveryClient.waitForWorldChange(config.getDiscoveryTimeout().getMillis(), TimeUnit.MILLISECONDS);
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
    }

    ServiceDiscoveryTransportFactory.registerDiscoveryClient(injectorId, discoveryClient, config);
}

From source file:alluxio.client.file.FileSystemUtils.java

/**
 * Shortcut for {@code waitCompleted(fs, uri, -1, TimeUnit.MILLISECONDS)}, i.e., wait for an
 * indefinite amount of time. Note that if a file is never completed, the thread will block
 * forever, so use with care./*from  w  w w .  j  a  v  a 2  s .c o m*/
 *
 * @param fs a {@link FileSystem} instance
 * @param uri the URI of the file on which the thread should wait
 * @return true if the file is complete when this method returns and false if the method timed out
 *         before the file was complete.
 * @throws IOException in case there are problems contacting the Alluxio master for the file
 *         status
 * @throws AlluxioException if an Alluxio Exception occurs
 * @throws InterruptedException if the thread receives an interrupt while waiting for file
 *         completion
 * @see #waitCompleted(FileSystem, AlluxioURI, long, TimeUnit)
 */
public static boolean waitCompleted(FileSystem fs, AlluxioURI uri)
        throws IOException, AlluxioException, InterruptedException {
    return FileSystemUtils.waitCompleted(fs, uri, -1, TimeUnit.MILLISECONDS);
}