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:de.taimos.httputils.Tester1.java

/**
 * // w w w . j  a  v a  2  s . com
 */
@Test
public void testGetAsync() throws InterruptedException {
    final CountDownLatch cdl = new CountDownLatch(1);
    WS.url("http://www.heise.de").getAsync(new HTTPResponseCallback() {

        @Override
        public void response(HttpResponse response) {
            Assert.assertEquals(WS.getStatus(response), 200);
            Assert.assertTrue(WS.isStatusOK(response));
            final String body = WS.getResponseAsString(response);
            Assert.assertNotNull(body);
            Assert.assertFalse(body.isEmpty());
            cdl.countDown();
        }

        @Override
        public void fail(Exception e) {
            System.out.println(e);
        }
    });
    Assert.assertTrue(cdl.await(10, TimeUnit.SECONDS));
}

From source file:hsa.awp.common.mail.MailStressTest.java

@Before
public void setUp() {
    service = new ThreadPoolExecutor(50, 50, 10, TimeUnit.SECONDS, queue);
}

From source file:com.shengpay.commons.bp.zk.ZkTemplate.java

/**
 * ZK???/*  www . j  a va 2 s . c  o  m*/
 * @param <V>
 * @param callback
 * @return
 * @throws Exception
 */
public <V> V doExecute(ZkCallBack<V> callback) throws Exception {
    if (callback == null)
        return null;

    logger.debug("Acquire the lock: {}", this.lockPath);

    if (!this.locker.acquire(30, TimeUnit.SECONDS)) {
        throw new IllegalStateException(" could not acquire the lock: " + this.lockPath);
    }

    try {

        return callback.doInZk(this.curator, this.lockPath);

    } finally {
        logger.debug("Releasing the lock: {}", this.lockPath);
        this.locker.release();
    }
}

From source file:io.gatling.jsonbenchmark.bytes.MainJacksonObjectBenchmark.java

@GenerateMicroBenchmark
@OutputTimeUnit(TimeUnit.SECONDS)
public void medium(BlackHole bh) throws Exception {
    bh.consume(parse(MEDIUM_BYTES));
}

From source file:org.fcrepo.federation.fedora3.itests.FedoraFederationIT.java

@BeforeClass
public static void ingestTestObjects() throws FedoraClientException, MalformedURLException {
    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
    connectionManager.setMaxTotal(Integer.MAX_VALUE);
    connectionManager.setDefaultMaxPerRoute(5);
    connectionManager.closeIdleConnections(3, TimeUnit.SECONDS);
    client = new DefaultHttpClient(connectionManager);

    String fedoraUrl = "http://localhost:" + System.getProperty("servlet.port") + "/fedora";
    fc = new FedoraClient(new FedoraCredentials(fedoraUrl, "fedoraAdmin", "fc"));

    pid = "it:1";
    ingestFoxml(pid);//ww w.  j a v a  2  s. c  o m
    dsid = "SIMPLE_TEXT";

}

From source file:uk.org.thegatekeeper.dw.booking.BookingServiceIT.java

@Test
public void testConcurrentBooking() throws Exception {
    JdiGateController controller = new JdiGateController(debugger);
    Gate gate = controller.stopFirstThread().inClass(PaymentService.class).beforeMethod("pay").build();

    final List<Throwable> exceptions = new ArrayList<Throwable>();
    Thread booking = new Thread(new Runnable() {
        public void run() {
            try {
                Request.Post("http://localhost:8080/booking/book/3/34").execute().returnContent().asString();
            } catch (Throwable t) {
                exceptions.add(t);//from   w w  w .  j  a  v a  2  s . c o m
            }
        }
    });

    booking.start();
    gate.waitFor(5, TimeUnit.SECONDS);

    String status = Request.Post("http://localhost:8080/booking/book/3/34").execute().returnContent()
            .asString();
    assertThat(status, containsString("\"success\":true"));

    gate.open();
    booking.join();

    assertEquals(1, exceptions.size());
}

From source file:com.alibaba.wasp.fserver.MetricsFServerWrapperImpl.java

public MetricsFServerWrapperImpl(final FServer fserver) {
    this.fserver = fserver;
    this.executor = MetricsExecutor.getExecutor();
    this.runnable = new FServerMetricsWrapperRunnable();
    this.executor.scheduleWithFixedDelay(this.runnable, PERIOD, PERIOD, TimeUnit.SECONDS);
}

From source file:com.redhat.developers.msa.hola.HolaResource.java

@GET
@Path("/hola")
@Produces("text/plain")
@ApiOperation("Returns the greeting in Spanish")
public String hola() {
    String hostname = System.getenv().getOrDefault("HOSTNAME", "unknown");
    String translation = ConfigResolver.resolve("hello").withDefault("Hola de %s").logChanges(true)
            // 5 Seconds cache only for demo purpose
            .cacheFor(TimeUnit.SECONDS, 5).getValue();
    return String.format(translation, hostname);

}

From source file:ratpack.codahale.metrics.internal.WebSocketReporter.java

@Inject
public WebSocketReporter(MetricRegistry registry, MetricsBroadcaster metricsBroadcaster,
        LaunchConfig launchConfig) {//from  w w w .  ja v a  2  s . co m
    super(registry, "websocket-reporter", MetricFilter.ALL, TimeUnit.SECONDS, TimeUnit.MILLISECONDS);
    this.metricsBroadcaster = metricsBroadcaster;
    String interval = launchConfig.getOther("metrics.scheduledreporter.interval", DEFAULT_INTERVAL);
    this.start(Long.valueOf(interval), TimeUnit.SECONDS);
}

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

@PreDestroy
public void stop() {
    Threads.normalShutdown(scheduledExecutorService, shutdownTimeout, TimeUnit.SECONDS);
}