List of usage examples for java.util.concurrent TimeUnit MILLISECONDS
TimeUnit MILLISECONDS
To view the source code for java.util.concurrent TimeUnit MILLISECONDS.
Click Source Link
From source file:com.taobao.tddl.common.sync.RowBasedReplicater.java
public void init() { /**//from w w w. j av a 2 s. c o m * CallerRunsPolicy: execute */ replicationExecutor = new ThreadPoolExecutor(threadPoolSize, threadPoolSize, 0L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(workQueueSize), new ThreadPoolExecutor.CallerRunsPolicy()); /** * LogDiscardPolicy */ deleteSyncLogExecutor = new ThreadPoolExecutor(1, 2, 0L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), new RejectedExecutionHandler() { public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { logger.warn("A DeleteSyncLogTask discarded"); } }); updateSyncLogExecutor = new ThreadPoolExecutor(1, 2, 0L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), new RejectedExecutionHandler() { public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { logger.warn("A UpdateSyncLogTask discarded"); } }); /** * */ final BucketTaker<RowBasedReplicationContext> deleteBucketTaker = new BucketTaker<RowBasedReplicationContext>( deleteSyncLogExecutor) { @Override public Runnable createTakeAwayTask(Collection<RowBasedReplicationContext> list) { return new DeleteSyncLogTask(list); } }; final BucketTaker<RowBasedReplicationContext> updateBucketTaker = new BucketTaker<RowBasedReplicationContext>( updateSyncLogExecutor) { @Override public Runnable createTakeAwayTask(Collection<RowBasedReplicationContext> list) { return new UpdateSyncLogTask(list); } }; deleteBucketSwitcher = new NoStrictBucketSwitcher<RowBasedReplicationContext>(deleteBucketTaker, DEFAULT_BATCH_DELETE_SIZE); updateBucketSwitcher = new NoStrictBucketSwitcher<RowBasedReplicationContext>(updateBucketTaker, DEFAULT_BATCH_UPDATE_SIZE); TDDLMBeanServer.registerMBean(this, "Replicater"); //JMX }
From source file:com.liferay.alerts.model.Alert.java
public String getFormattedTimestamp() { String formattedTimestamp;//ww w . j av a2 s.co m long elapsedTime = System.currentTimeMillis() - _timestamp; if (elapsedTime < DateUtils.MINUTE_IN_MILLIS) { formattedTimestamp = String.format("%ds", TimeUnit.MILLISECONDS.toSeconds(elapsedTime)); } else if (elapsedTime < DateUtils.HOUR_IN_MILLIS) { formattedTimestamp = String.format("%dm", TimeUnit.MILLISECONDS.toMinutes(elapsedTime)); } else if (elapsedTime < DateUtils.DAY_IN_MILLIS) { formattedTimestamp = String.format("%dh", TimeUnit.MILLISECONDS.toHours(elapsedTime)); } else { formattedTimestamp = String.format("%dd", TimeUnit.MILLISECONDS.toDays(elapsedTime)); } return formattedTimestamp; }
From source file:com.watchrabbit.crawler.executor.service.CrawlExecutorServiceImpl.java
@Override public void processPage(CrawlForm form) { Collection<Cookie> session = authServiceFacade.getSession(form.getDomain()); RemoteWebDriver driver = remoteWebDriverFactory.produceDriver(); try {// w w w . j av a2 s . c o m Stopwatch stopwatch = Stopwatch.createStarted(() -> enableSession(driver, form, session)); LOGGER.debug("Finished loading {} in {}", form.getUrl(), stopwatch.getExecutionTime(TimeUnit.MILLISECONDS)); List<LinkDto> links = collectLinks(driver).stream() .map(link -> new LinkDto.Builder().withUrl(link).build()).collect(toList()); if (form.isGateway()) { LOGGER.debug("Processing gateway {}", form.getUrl()); List<String> keywords = keywordGenerateStrategy.generateKeywords(form, driver); links.addAll(keywords.stream() .map(keyword -> new LinkDto.Builder().withKeyword(keyword).withUrl(form.getUrl()).build()) .collect(toList())); } double importanceFactor = crawlListener.accept(form.getId(), driver); managerServiceFacade.consumeResult(new CrawlResult.Builder().withDomain(form.getDomain()) .withMiliseconds(stopwatch.getExecutionTime(TimeUnit.MILLISECONDS)).withUrl(form.getUrl()) .withLinks(links).withId(form.getId()).withImportanceFactor(importanceFactor).build()); } catch (Exception ex) { LOGGER.error("Execption on processing page " + form.getUrl(), ex); managerServiceFacade.onError(form); } finally { remoteWebDriverFactory.returnWebDriver(driver); } }
From source file:com.mapr.synth.samplers.ArrivalSampler.java
@SuppressWarnings("UnusedDeclaration") public void setRate(String rate) { Matcher m = ratePattern.matcher(rate); if (m.matches()) { // group(1) is the number, group(2) is either empty (default to /s) or /d or some such. TimeUnit sourceUnit = (m.groupCount() > 1) ? unitMap.get(m.group(2).substring(1)) : TimeUnit.SECONDS; double count = Double.parseDouble(m.group(1)); this.meanInterval = TimeUnit.MILLISECONDS.convert(1, sourceUnit) / count; } else {/*w w w . java2 s . c o m*/ throw new IllegalArgumentException(String.format("Invalid rate argument: %s", rate)); } }
From source file:eu.artofcoding.beetlejuice.spring.SpringContextHelper.java
private void waitForExecutors(List<ExecutorService> executorServices) { long shutdownDeadline = System.currentTimeMillis() + 1000; for (ExecutorService executorService : executorServices) { try {//from ww w . j a v a 2 s . com if (!executorService.awaitTermination(shutdownDeadline - System.currentTimeMillis(), TimeUnit.MILLISECONDS)) { logger.info(String.format("Executor service %s failed to terminate", executorService)); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); logger.warn(String.format("Interrupted while shutting down executor service %s", executorService)); throw new RuntimeException("Interrupted while shutting down", e); } if (System.currentTimeMillis() > shutdownDeadline) { logger.warn("Timed out before waiting for all executor services"); } } }
From source file:com.tongbanjie.tarzan.server.client.ClientManager.java
public void scanNotActiveChannel() { try {/* w w w.ja v a2 s .com*/ if (this.groupChannelLock.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) { try { for (final Entry<String, HashMap<Channel, ClientChannelInfo>> entry : this.groupChannelTable .entrySet()) { final String group = entry.getKey(); final HashMap<Channel, ClientChannelInfo> chlMap = entry.getValue(); Iterator<Entry<Channel, ClientChannelInfo>> it = chlMap.entrySet().iterator(); while (it.hasNext()) { Entry<Channel, ClientChannelInfo> item = it.next(); final ClientChannelInfo info = item.getValue(); long diff = System.currentTimeMillis() - info.getLastUpdateTimestamp(); if (diff > CHANNEL_EXPIRED_TIMEOUT) { it.remove(); LOGGER.warn( "SCAN: remove expired channel[{}] from ClientManager groupChannelTable, client group name: {}", RpcHelper.parseChannelRemoteAddr(info.getChannel()), group); RpcHelper.closeChannel(info.getChannel()); } } } } finally { this.groupChannelLock.unlock(); } } else { LOGGER.warn("ClientManager scanNotActiveChannel lock timeout"); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); LOGGER.error("", e); } }
From source file:edu.umich.robot.soar.CarryIL.java
private void updateLingerMillis(Integer seconds) { lingerMillis = TimeUnit.MILLISECONDS.convert(seconds, TimeUnit.SECONDS); }
From source file:io.github.seleniumquery.browser.driver.SeleniumQueryDriver.java
private void setDriverTimeout() { // TODO unit test this.webDriver.manage().timeouts().implicitlyWait(SeleniumQueryConfig.getGlobalTimeout(), TimeUnit.MILLISECONDS); }
From source file:com.letv.demo.web.GiftController.java
/** * Close to the reality use case, one use can only get one gift. * * @param uid//w w w. j a v a 2 s. c om * @return */ @RequestMapping("/gift/{uid}") public String gift(@PathVariable String uid) { long gift = redissonService.getAndDecrement(); if (gift > 0) { // make sure only RedissonService.giftCount request will pass through the cache counter layer String key = uid; // has (s)he been got it? RLock lock = redissonService.getLock(); // Lock time-to-live support // releases lock automatically after 10 seconds if unlock method not invoked lock.lock(500, TimeUnit.MILLISECONDS); try { String existed = repository.getString(key); if (existed != null) { log.info("User.uid = {} has got the gift: {}", key, existed); return "ALREADY-GOT"; } else { // if use RDBMS, eg., mysql // we should push the data into mq // then let the consumer do below -- persist to disk String value = Long.toString(gift); repository.setString(key, value); log.info("persistent the status: {} = {}", key, value); // get the value back and return String back = repository.getString(key); return key + ": " + back; } } finally { lock.unlock(); } } else { log.info("all gifts are consumed."); return "NOT-FOUND"; } }
From source file:business.controllers.UserController.java
@RequestMapping(value = "/register/users/activate/{token}", method = RequestMethod.GET) public ResponseEntity<Object> activateUser(@PathVariable String token) { ActivationLink link = activationLinkRepository.findByToken(token); if (link == null) { log.warn("Activation link not found."); return new ResponseEntity<Object>(HttpStatus.BAD_REQUEST); }/*from w w w . j a v a 2 s . c o m*/ // Check that the link has been issued in the previous week log.info("Activation link: expiry hours = " + activationLinkExpiryHours); long linkAge = TimeUnit.MILLISECONDS.toHours(new Date().getTime() - link.getCreationDate().getTime()); // hours log.info("Activation link age in hours: " + linkAge); if (linkAge <= activationLinkExpiryHours) { User user = link.getUser(); user.setEmailValidated(true); userService.save(user); activationLinkRepository.delete(link); log.info("User validated."); return new ResponseEntity<Object>(HttpStatus.OK); } else { // The activation link doesn't exist or is outdated! log.warn("Activation link expired."); return new ResponseEntity<Object>(HttpStatus.BAD_REQUEST); } }