Java 8 TimeUnit - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 TimeUnit class.

This code example shows how to use the following methods: toNanos
    private final TimeUnit rateUnit;
    private final ScheduledFuture<?> future;
 
    public MeterMetric(ScheduledExecutorService tickThread, TimeUnit rateUnit) {
        this.rateUnit = rateUnit;
        this.future = tickThread.scheduleAtFixedRate(new Runnable() {
            @Override 
            public void run() { 
                tick(); 
            } 
        }, INTERVAL, INTERVAL, TimeUnit.SECONDS);
    } 
 
    public TimeUnit rateUnit() {
        return rateUnit;
    } 
 
    /** 
     * Updates the moving averages. 
     */ 

8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: sleep
 
        // check that the connector is live 
        String cURL = "http://" + url.getHost() + ":8181";
 
        //this tests for default content serving... 
        String response = HttpRequest.get(cURL, 10, TimeUnit.SECONDS);
        assertTrue("Invalid response: " + response, response.indexOf("JBoss") >=0);
 
 
        // remove connector 
        cli.sendLine("/subsystem=undertow/server=default-server/http-listener=test-listener:remove{allow-resource-service-restart=true}"); 
        result = cli.readAllAsOpResult();
        assertTrue(result.isIsOutcomeSuccess());
 
        cli.sendLine("/socket-binding-group=standard-sockets/socket-binding=test:remove"); 
        result = cli.readAllAsOpResult();
        assertTrue(result.isIsOutcomeSuccess());
 
        // check that the connector is no longer live 
        Thread.sleep(5000);

8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: toMillis
This code example shows how to use the following methods: toNanos
     * @param alpha        the smoothing constant 
     * @param interval     the expected tick interval 
     * @param intervalUnit the time unit of the tick interval 
     */ 
    public EWMA(double alpha, long interval, TimeUnit intervalUnit) {
        this.interval = intervalUnit.toNanos(interval);
        this.alpha = alpha;
    } 
 
    /** 
     * Update the moving average with a new value. 
     * 
     * @param n the new value 
     */ 
    public void update(long n) {
        uncounted.add(n);
    } 
 
    /** 
     * Mark the passage of time and decay the current rate accordingly. 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: toMillis
    } 
 
    @Override 
    public synchronized Object get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
        if (!isDone()) { 
            wait(unit.toMillis(timeout));
            if (!isDone()) { 
                throw MESSAGES.failToCompleteTaskBeforeTimeOut(timeout, unit);
            } 
        } 
        if (cancelledFlag.get()) {
            throw MESSAGES.taskWasCancelled(); 
        } else if (failed != null) {
            throw new ExecutionException(failed);
        } 
        return result;
    } 
} 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Java 8 TimeUnit Questions & Answers:

See Code Examples for Java 8 TimeUnit Methods: