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:edu.uci.ics.crawler4j.fetcher.IdleConnectionMonitorThread.java

@Override
public void run() {
    try {//from   w ww . j a v  a 2 s .  c o m
        while (!shutdown) {
            synchronized (this) {
                wait(5000);
                connMgr.closeExpiredConnections();
                connMgr.closeIdleConnections(30, TimeUnit.SECONDS);
            }
        }
    } catch (InterruptedException ex) {
    }
}

From source file:controllers.Mock.java

private static F.Promise<Result> respond(final JsonNode json, final int delayInSeconds) {
    return F.Promise.timeout(ok(json), delayInSeconds, TimeUnit.SECONDS);
}

From source file:barChart1.BarChartDemo.java

/**
 * Starting point for the demonstration application.
 *
 * @param args  ignored./*from   w  w w.  j a  va  2  s  .  c  o m*/
 */
public static void main(String[] args) {

    // Demo to buy tickets to the EK 2016

    System.out.println("Hello UEFA 2016 !!!");

    statistics = "";

    JOptionPane.showMessageDialog(null, "Belgium versus Italy demo start");

    driver = new FirefoxDriver();
    wait = new WebDriverWait(driver, 500);

    //Open Home Page
    driver.manage().window().maximize();
    driver.get("http://www.uefa.com/");

    wait.until(ExpectedConditions.visibilityOfElementLocated(
            By.xpath("//div/header/nav/div/div/ul/li/a[text() = 'UEFA EURO 2016']")));

    driver.findElement(By.xpath("//div/header/nav/div/div/ul/li/a[text() = 'UEFA EURO 2016']")).click();

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div//nav/div/div/ul/li/a[ text() = 'Teams']")));

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div//nav/div/div/ul/li/a[ text() = 'Matches']")))
            .click();

    wait.until(ExpectedConditions.visibilityOfElementLocated(
            By.xpath("//div/div//div//div/a[text() = 'Select your team and follow their EURO journey']")));

    driver.findElement(
            By.xpath("//div/div//div//div/a[text() = 'Select your team and follow their EURO journey']"))
            .click();

    wait2Secs();

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div//ul/li/span[text()='Belgium']")));

    driver.findElement(By.xpath("//div/div/div//ul/li/span[text()='Belgium']")).click();

    // Belgium
    wait2Secs();

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("(//div/table[1]/tbody/tr/td/div/a[text()='21.00'])[1]")));

    driver.findElement(By.xpath("(//div/table[1]/tbody/tr/td/div/a[text()='21.00'])[1]")).click();

    wait2Secs();

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a/span[text()='Pre-match']")));

    // Go to the statistics

    driver.get("http://www.uefa.com/uefaeuro/season=2016/statistics/index.html");

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a/span[text()='Teams']")));

    driver.findElement(By.xpath("//a/span[text()='Teams']")).click();

    // Look up the statistics for Belgium and Italy

    getOverviewStats("BE", "ITA", "Belgium", "Italy");

    wait.until(
            ExpectedConditions.visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Goals']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Goals']")).click();

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Belgium");
    ;

    wait2Secs();

    // getGoalsStats("BE","ITA","Belgium","Italy");

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Attempts']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Attempts']")).click();

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Belgium");
    ;

    wait2Secs();

    wait.until(
            ExpectedConditions.visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Passes']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Passes']")).click();

    wait2Secs();

    // Italy

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy");
    ;

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Overview']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Overview']")).click();

    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy");
    ;

    wait.until(
            ExpectedConditions.visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Goals']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Goals']")).click();

    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy");
    ;

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Attempts']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Attempts']")).click();

    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy");
    ;

    wait.until(
            ExpectedConditions.visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Passes']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Passes']")).click();

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy");
    ;

    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

    JOptionPane.showMessageDialog(null, "Belgium versus Italy : \n" + statistics);

    BarChartDemo demo = new BarChartDemo("Belgium vs Italy");
    demo.pack();
    RefineryUtilities.centerFrameOnScreen(demo);
    demo.setVisible(true);

}

From source file:org.schedoscope.metascope.service.MetascopeStatusService.java

@PostConstruct
public void init() {
    this.statusCache = CacheBuilder.newBuilder().maximumSize(2000000).expireAfterWrite(60, TimeUnit.SECONDS)
            .build();
}

From source file:org.aliuge.crawler.fetcher.IdleConnectionMonitorThread.java

@Override
public void run() {
    try {// w ww .j av a 2  s  .c  o m
        while (!shutdown) {
            synchronized (this) {
                wait(5000);
                connMgr.closeExpiredConnections();
                connMgr.closeIdleConnections(30, TimeUnit.SECONDS);
                System.out.println("#getAvailable=" + connMgr.getTotalStats().getAvailable());
            }
        }
    } catch (InterruptedException ex) {
    }
}

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

@BeforeClass
public static void setup() {
    DefaultServer.setRootHandler(/*  w  ww .jav  a2 s.  c o  m*/
            new BlockingHandler(Handlers.requestLimitingHandler(2, N_THREADS, new HttpHandler() {
                @Override
                public void handleRequest(HttpServerExchange exchange) throws Exception {
                    int res = count.incrementAndGet();
                    try {
                        if (!latch.await(20, TimeUnit.SECONDS)) {
                            exchange.setStatusCode(500);
                        } else {
                            exchange.getOutputStream().write(("" + res).getBytes("US-ASCII"));
                        }
                    } finally {
                        count.decrementAndGet();
                    }
                }
            })));

}

From source file:Main.java

/**
 * Convert a millisecond duration to a string format
 *
 * @param millis//from w w w.ja  va2  s .  com
 *      A duration to convert to a string form
 * @return A string of the form "X Days Y Hours Z Minutes A Seconds".
 */
public static String getDurationBreakdown(long millis, final boolean showMS) {
    if (millis <= 0) {
        return "-";
    }

    final long days = TimeUnit.MILLISECONDS.toDays(millis);
    millis -= TimeUnit.DAYS.toMillis(days);
    final long hours = TimeUnit.MILLISECONDS.toHours(millis);
    millis -= TimeUnit.HOURS.toMillis(hours);
    final long minutes = TimeUnit.MILLISECONDS.toMinutes(millis);
    millis -= TimeUnit.MINUTES.toMillis(minutes);
    final long seconds = TimeUnit.MILLISECONDS.toSeconds(millis);
    millis -= TimeUnit.SECONDS.toMillis(seconds);

    final StringBuilder sb = new StringBuilder();
    if (days > 0) {
        sb.append(days);
        sb.append("d ");
    }
    if (hours > 0) {
        sb.append(String.format("%02d", hours));
        sb.append("h ");
    }
    if (minutes > 0) {
        sb.append(String.format("%02d", minutes));
        sb.append("min ");
    }
    if (seconds > 0) {
        sb.append(String.format("%02d", seconds));
        sb.append("s");
    }
    if ((seconds <= 0) && (millis > 0) && showMS) {
        sb.append(String.format("%02d", millis));
        sb.append("ms");
    }

    return sb.toString();
}

From source file:com.saasovation.identityaccess.resource.AbstractResource.java

protected CacheControl cacheControlFor(int aNumberOfSeconds) {
    return CacheControl.maxAge(30, TimeUnit.SECONDS);
}

From source file:edu.wpi.checksims.util.threading.ParallelAlgorithm.java

/**
 * @param threads Number of threads to be used for execution
 */// w  w  w.  j  a v a  2  s.  c om
public static void setThreadCount(int threads) {
    checkArgument(threads > 0,
            "Attempted to set number of threads to " + threads + ", but must be positive integer!");

    threadCount = threads;
    executor.shutdown();
    // Set up the executor again with the new thread count
    executor = new ThreadPoolExecutor(threadCount, threadCount, 1, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(), new ThreadPoolExecutor.AbortPolicy());
}

From source file:com.camel.crawler.WebCrawler.java

public void fetchWeb(String url) throws IOException {
    client.setConnectTimeout(2, TimeUnit.SECONDS);
    Request request = new Request.Builder().url(url).build();
    Response response = client.newCall(request).execute();

    int responseCode = response.code();

    if (responseCode == 200) {
        extraInfo(response.body().string());
    } else {/* ww w .  j a v a2  s . c o  m*/
        System.out.println("got error page");
    }
}