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.manning.androidhacks.hack040.util.LIFOThreadPoolProcessor.java

public LIFOThreadPoolProcessor(int threadCount) {
    executor = new ThreadPoolExecutor(threadCount, threadCount, 0, TimeUnit.SECONDS, opsToRun);
}

From source file:com.guang.eunormia.common.cache.DefaultLocalCache.java

@SuppressWarnings("unchecked")
private void init() {
    caches = new ConcurrentHashMap[moduleSize];

    for (int i = 0; i < moduleSize; i++) {
        caches[i] = new ConcurrentHashMap<K, SoftReference<V>>();
    }/*from ww  w  . j a  v  a 2 s.  com*/

    expiryCache = new ConcurrentHashMap<K, Long>();

    scheduleService = Executors.newScheduledThreadPool(1);

    scheduleService.scheduleAtFixedRate(new CheckOutOfDateSchedule(caches, expiryCache), 0, expiryInterval * 60,
            TimeUnit.SECONDS);

    if (Logger.isInfoEnabled()) {
        Logger.info("DefaultCache CheckService is start!");
    }
}

From source file:com.pva.QueryGeneratorImpl.java

protected void run() throws Exception {
    while (isRunning()) {
        List<Price> prices = timeSeriesService.getPrices();

        for (Price price : prices) {
            price.setSymbol(symbolToLekFormat(price.getSymbol()));
        }/*w ww .  ja  v  a 2s . c  o m*/

        if (prices != null && !prices.isEmpty()) {
            // I want to add the tickets all the tickets at once
            TimeSeries timeSeries = new TimeSeries(prices);
            addToTimeSeriesQueue(timeSeries);
            generateCount++;
        }
        pollCount++;
        LOGGER.info(String.format("Sleeping for %d seconds....", sleepInterval));
        TimeUnit.SECONDS.sleep(sleepInterval);
    }
}

From source file:de.codecentric.batch.metrics.GraphiteMetricsExporter.java

public GraphiteMetricsExporter(MetricRegistry metricRegistry, final MetricReader metricReader, String server,
        Integer port, String environment) {
    Graphite graphite = new Graphite(new InetSocketAddress(server, port));
    MetricFilter filter = new MetricFilter() {
        @Override//from  w  w w  .ja v a2 s  .c  o m
        public boolean matches(String name, Metric metric) {
            org.springframework.boot.actuate.metrics.Metric<?> bootMetric = metricReader.findOne(name);
            if (bootMetric.getTimestamp().after(lastExport)) {
                return true;
            }
            return false;
        }
    };
    reporter = GraphiteReporter.forRegistry(metricRegistry).prefixedWith(environment)
            .convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter(filter)
            .build(graphite);
}

From source file:com.pubkit.platform.persistence.impl.RedisDaoImpl.java

@Override
public void saveAccessToken(String email, String accessToken) {
    ValueOperations<String, String> ops = this.redisTemplate.opsForValue();
    if (pkConfig.getAccessTokenExpirationTime() == 0) {
        ops.set(accessToken, email, 3600, TimeUnit.SECONDS);
    } else {/*ww w . j a v a 2 s.  c  o  m*/
        ops.set(accessToken, email, pkConfig.getAccessTokenExpirationTime(), TimeUnit.SECONDS);
    }
    ops.set(email, accessToken);
}

From source file:org.eclipse.sw360.datahandler.couchdb.AttachmentStreamConnectorTest.java

@Before
public void setUp() throws Exception {
    attachmentStreamConnector = new AttachmentStreamConnector(connector, attachmentContentDownloader,
            durationOf(5, TimeUnit.SECONDS));
}

From source file:org.smartfrog.services.anubis.SmokeTest.java

public void testInProcess() throws Exception {
    TestNodeCfg.nextMagic();/*  w ww.  ja v a  2s  .co m*/
    String stateName = "Whip It";
    int maxSleep = 500;
    int messageCount = 10;
    ArrayList<Node> nodes = new ArrayList<Node>();
    CountDownLatch launchLatch = new CountDownLatch(configurations.length);
    CountDownLatch startLatch = new CountDownLatch(configurations.length);
    CountDownLatch endLatch = new CountDownLatch(configurations.length);
    for (Class<?> config : configurations) {
        nodes.add(getNode(config, stateName, messageCount, maxSleep, launchLatch, startLatch, endLatch,
                configurations.length));
    }
    boolean stabilized = launchLatch.await(120, TimeUnit.SECONDS);
    assertTrue("Partition did not stabilize", stabilized);
    System.out.println("Partition stabilized");
    for (Node node : nodes) {
        node.start();
    }
    boolean started = startLatch.await(60, TimeUnit.SECONDS);
    assertTrue("Not all nodes started", started);
    System.out.println("Partition started");
    boolean ended = endLatch.await(60, TimeUnit.SECONDS);
    assertTrue("Not all messages were received: " + findMissing(nodes), ended);
    for (Node node : nodes) {
        node.shutDown();
    }
    for (Node sender : nodes) {
        List<SendHistory> sent = sender.getSendHistory();
        assertEquals(messageCount, sent.size());
        for (Node receiver : nodes) {
            List<ValueHistory> received = receiver.getValueHistory(sender.getIdentity());
            assertNotNull("Received no history from " + sender.getIdentity(), received);
            int lastCounter = -1;
            boolean first = true;
            List<ValueHistory> filtered = new ArrayList<ValueHistory>();
            for (ValueHistory msg : received) {
                if (msg.value == null) {
                    continue;
                }
                filtered.add(msg);
                assertEquals(Action.NEW, msg.action);
                if (first) {
                    first = false;
                    lastCounter = (Integer) msg.value;
                } else {
                    int counter = (Integer) msg.value;
                    assertEquals(String.format("invalid msg received by %s : %s", receiver.getIdentity(), msg),
                            lastCounter + 1, counter);
                    lastCounter = counter;
                }
            }
            for (int i = 0; i < sent.size(); i++) {
                assertEquals(sent.get(i).value, filtered.get(i).value);
            }
        }
    }
}

From source file:com.couchbase.example.CBJavaSDKHarness.repository.GenericRepository.java

public String findById(String id) {
    if (isBlank(id)) {
        throw new IllegalArgumentException("id is blank");
    }/*from   w w w  .  jav a  2  s  . c om*/
    JsonDocument doc = null;
    try {
        doc = bucket.get(id, 1, TimeUnit.SECONDS);
    } catch (CouchbaseException e) {
        throw new RepositoryException(e);
    }
    return fromJsonDocument(doc);
}

From source file:com.aliyun.oss.common.comm.TimeoutServiceClient.java

public TimeoutServiceClient(ClientConfiguration config) {
    super(config);

    int processors = Runtime.getRuntime().availableProcessors();
    executor = new ThreadPoolExecutor(processors * 5, processors * 10, 60L, TimeUnit.SECONDS,
            new ArrayBlockingQueue<Runnable>(processors * 100), Executors.defaultThreadFactory(),
            new ThreadPoolExecutor.CallerRunsPolicy());
    executor.allowCoreThreadTimeOut(true);
}

From source file:com.rackspacecloud.blueflood.cache.TtlCacheTest.java

@Before
public void setupCache() {
    loadCount = new AtomicLong(0);
    buildCount = new AtomicLong(0);
    twoSecondCache = new TtlCache("Test", new TimeValue(2, TimeUnit.SECONDS), 5, new InternalAPI() {
        public Account fetchAccount(String tenantId) throws IOException {
            loadCount.incrementAndGet();
            if (IOException.class.getName().equals(tenantId))
                throw new IOException("Error retrieving account from internal API");
            else if (HttpResponseException.class.getName().equals(tenantId))
                throw new HttpResponseException(404, "That account does not exist");
            else/*w w  w . j av a  2s.co m*/
                return Account.fromJSON(AccountTest.JSON_ACCOUNTS.get(tenantId));
        }

        @Override
        public List<AccountMapEntry> listAccountMapEntries() throws IOException {
            throw new RuntimeException("Not implemented for this test");
        }
    }) {
        @Override
        protected Map<ColumnFamily<Locator, Long>, TimeValue> buildTtlMap(Account acct) {
            buildCount.incrementAndGet();
            return super.buildTtlMap(acct);
        }
    };
}