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.aol.advertising.qiao.management.metrics.StatsCollector.java

/**
 * Start the collection process.//w  w w  .j  av a2s  . c  o m
 */
public void start() {
    schedulerHandler = scheduler.scheduleAtFixedRate(this, initDelaySecs, intervalSecs, TimeUnit.SECONDS);
    logger.info("stats collector starts");
    running = true;
}

From source file:org.surfnet.oaaas.selenium.SeleniumSupport.java

private static void initDriver(WebDriver remoteWebDriver) {
    SeleniumSupport.driver = remoteWebDriver;
    SeleniumSupport.driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override//  w  ww.ja  v  a  2 s  .  c  om
        public void run() {
            if (driver != null) {
                driver.quit();
            }
        }
    });
}

From source file:org.openbase.bco.ontology.lib.commun.monitor.ServerConnection.java

/**
 * Method creates a monitoring thread to observe the connection state between ontology manager and ontology server. In case the server can't be
 * reached, an observable informs./* w ww . ja va 2  s  .c om*/
 *
 * @throws NotAvailableException is thrown in case there is no thread available.
 */
public static void newServerConnectionObservable() throws NotAvailableException {
    GlobalScheduledExecutorService.scheduleWithFixedDelay(() -> {
        try {
            try {
                final HttpClient httpclient = HttpClients.createDefault();
                final HttpGet httpGet = new HttpGet(OntConfig.getOntologyPingUrl());
                final HttpResponse httpResponse = httpclient.execute(httpGet);

                SparqlHttp.checkHttpRequest(httpResponse, null);
                SERVER_STATE_OBSERVABLE.notifyObservers(ConnectionState.CONNECTED);
            } catch (IOException | CouldNotPerformException ex) {
                SERVER_STATE_OBSERVABLE.notifyObservers(ConnectionState.DISCONNECTED);
            }
        } catch (CouldNotPerformException ex) {
            ExceptionPrinter.printHistory(ex, LOGGER, LogLevel.ERROR);
        }
    }, 0, 1, TimeUnit.SECONDS);
}

From source file:com.mycollab.module.ecm.service.impl.DriveInfoServiceImpl.java

@Override
public void saveOrUpdateDriveInfo(@CacheKey DriveInfo driveInfo) {
    Integer sAccountId = driveInfo.getSaccountid();
    DriveInfoExample ex = new DriveInfoExample();
    ex.createCriteria().andSaccountidEqualTo(sAccountId);
    Lock lock = DistributionLockUtil.getLock("ecm-service" + sAccountId);
    try {//  w  ww. ja v  a2s  .  c o  m
        if (lock.tryLock(15, TimeUnit.SECONDS)) {
            if (driveInfoMapper.countByExample(ex) > 0) {
                driveInfo.setId(null);
                driveInfoMapper.updateByExampleSelective(driveInfo, ex);
            } else {
                driveInfoMapper.insert(driveInfo);
            }
        }
    } catch (Exception e) {
        LOG.error("Error while save drive info " + BeanUtility.printBeanObj(driveInfo), e);
    } finally {
        DistributionLockUtil.removeLock("ecm-service" + sAccountId);
        lock.unlock();
    }
}

From source file:com.thesoftwareguild.flightmaster.queryExecutor.ExecutorPQ.java

/**
 * This method starts the single thread PQ. It should be called when the
 * program is initialized.// w w w .j av a 2  s . co  m
 */
@PostConstruct
@Override
public void run() {
    queryExecutor.schedule(pqThread, 1, TimeUnit.SECONDS);

    RequestDao requestDao = context.getBean("requestDaoJdbc", RequestDao.class);
    List<RequestParameters> liveRequests = requestDao.getLiveRequests();
    for (RequestParameters liveRequest : liveRequests) {
        Request request = context.getBean(Request.class);
        request.setRequestParameters(liveRequest);
        request.setExecutionTime(liveRequest.getNextQueryTime());
        addToExecutor(request);
    }
    logger.info("PQ Thread started and live requests loaded");
}

From source file:com.fusesource.forge.jmstest.executor.AbstractBenchmarkExecutionContainer.java

synchronized public void start(String[] args) {
    handleArguments(args);/*from ww  w.ja v a  2  s  .c  om*/
    if (!started) {
        if (isAutoTerminate()) {
            executor = new TerminatingThreadPoolExecutor("BenchmarkExecutor", 1, 1, 10, TimeUnit.SECONDS,
                    new LinkedBlockingQueue<Runnable>());
        } else {
            executor = new ThreadPoolExecutor(1, 1, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
        }
        executor.submit(this);
        started = true;
    }
}

From source file:com.appleframework.monitor.action.MongoAction.java

@RequestMapping(value = "/projects/{projectName}/mongo/console", method = RequestMethod.POST)
public @ResponseBody BasicDBObject test(ModelMap map, @PathVariable String projectName, String script,
        Integer timeout) throws IOException, ExecutionException, TimeoutException, InterruptedException {

    Project project = projectService.findProject(projectName);
    FutureTask<CommandResult> futureTask = taskService.runScript(script, project);

    BasicDBObject result = null;//from w ww. ja v a2  s . co m
    timeout = timeout != null ? timeout : 60;
    try {
        result = futureTask.get(timeout, TimeUnit.SECONDS);
    } catch (Exception e) {
        logger.error("execute task fail " + script, e);
        result = new BasicDBObject("err", e.toString());
    }
    logger.debug("run mongo script =[{}] ,result=[{}]", script, result);

    return result;
}

From source file:com.walmart.gatling.MonitoringConfiguration.java

public ConsoleReporter consoleReporter(MetricRegistry registry) {
    ConsoleReporter reporter = ConsoleReporter.forRegistry(registry).convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS).build();
    reporter.start(10, TimeUnit.SECONDS);
    return reporter;
}

From source file:com.epam.reportportal.auth.event.UiAuthenticationFailureEventHandler.java

public UiAuthenticationFailureEventHandler() {
    super();//from   w w  w.  j a  v  a  2 s . c  o  m
    failures = CacheBuilder.newBuilder().maximumSize(MAXIMUM_SIZE)
            .expireAfterWrite(EXPIRATION_SECONDS, TimeUnit.SECONDS)
            .build(new CacheLoader<String, AtomicInteger>() {
                @Override
                public AtomicInteger load(String key) {
                    return new AtomicInteger(0);
                }
            });
}

From source file:com.espertech.esper.multithread.TestMTIsolation.java

private void tryIsolated(int numThreads, int numLoops) throws Exception {
    Configuration config = SupportConfigFactory.getConfiguration();
    config.getEngineDefaults().getViewResources().setShareViews(false);
    config.addEventType("SupportBean", SupportBean.class);
    EPServiceProvider engine = EPServiceProviderManager.getDefaultProvider(config);
    engine.initialize();// w ww .  ja  va 2 s .c om

    // execute
    ExecutorService threadPool = Executors.newFixedThreadPool(numThreads);
    Future future[] = new Future[numThreads];
    ReentrantReadWriteLock sharedStartLock = new ReentrantReadWriteLock();
    sharedStartLock.writeLock().lock();
    for (int i = 0; i < numThreads; i++) {
        future[i] = threadPool.submit(new IsolateUnisolateCallable(i, engine, numLoops));
    }
    Thread.sleep(100);
    sharedStartLock.writeLock().unlock();

    threadPool.shutdown();
    threadPool.awaitTermination(10, TimeUnit.SECONDS);

    for (int i = 0; i < numThreads; i++) {
        assertTrue((Boolean) future[i].get());
    }
}