List of usage examples for java.util TimerTask TimerTask
protected TimerTask()
From source file:au.org.intersect.dms.wn.impl.WorkerNodeImpl.java
private TimerTask makeChecker() { return new TimerTask() { public void run() { for (JobTracker tracker : trackers.values()) { if (!tracker.progressed()) { LOGGER.info("Worker checker: killing blocked job " + tracker.getJobId()); tracker.getThread().interrupt(); } else { tracker.stampProgress(); }//from www . java 2 s .co m } } }; }
From source file:org.geppetto.samplesimulation.SimulationServlet.java
private void startClientUpdateTimer() { _simTimer = new Timer( SimulationServlet.class.getSimpleName() + " - Timer - " + new java.util.Date().getTime()); _simTimer.scheduleAtFixedRate(new TimerTask() { @Override//ww w.j av a2s .c o m public void run() { try { update(); } catch (RuntimeException e) { // log.error("Caught to prevent timer from shutting down", e); } } }, UPDATE_CYCLE, UPDATE_CYCLE); }
From source file:burstcoin.observer.service.NetworkService.java
private void startCheckNetworkTask() { timer.schedule(new TimerTask() { @Override// ww w.ja va2 s. c o m public void run() { // only start if previous is finished if (miningInfoLookup.isEmpty() || new Date().getTime() - (5 * 60 * 1000) > lastUpdate.getTime()) { miningInfoLookup.clear(); try { lastUpdate = new Date(); for (String networkServerUrl : ObserverProperties.getNetworkServerUrls()) { GetMiningInfoTask getMiningInfoTask = beanFactory.getBean(GetMiningInfoTask.class, networkServerUrl); taskExecutor.execute(getMiningInfoTask); } } catch (Exception e) { LOG.error("Failed receiving Network data."); } } } }, 1200, ObserverProperties.getNetworkRefreshInterval()); }
From source file:com.github.matthesrieke.realty.CrawlerServlet.java
@Override public void init() throws ServletException { super.init(); this.listTemplate = Util.parseStream(getClass().getResourceAsStream("index-template.html")); this.groupTemplate = Util.parseStream(getClass().getResourceAsStream("group-template.html")); this.properties = new Properties(); InputStream is = getClass().getResourceAsStream("/config.properties"); if (is == null) { is = getClass().getResourceAsStream("/config.properties.default"); }/*from w ww . j av a 2 s . c o m*/ try { this.properties.load(is); } catch (IOException e1) { logger.warn(e1.getMessage(), e1); throw new ServletException("Could not init properties!", e1); } initializeCrawlers(); readCrawlingLinks(); String preferredDatabaseLocation = properties.getProperty("DATABASE_DIR"); storage = new H2Storage(preferredDatabaseLocation); this.timer = new Timer(); Integer crawlPeriod = Util.getIntegerProperty(this.properties, "crawlPeriodHours", 6); logger.info(String.format("Scheduling crawl every %s hours.", crawlPeriod)); this.timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { logger.info("Starting to parse ad entries..."); DateTime now = new DateTime(); int insertedCount = 0; int crawlerCount = 0; try { for (String baseLink : crawlLinks) { logger.info("Baselink = " + baseLink); Crawler crawler; try { crawler = resolveCrawler(baseLink); } catch (UnsupportedBaseLinkException e1) { logger.warn(e1.getMessage(), e1); break; } crawlerCount++; String link; int page = crawler.getFirstPageIndex(); while (true) { Thread.sleep(1000); logger.info("Parsing page " + page); link = crawler.prepareLinkForPage(baseLink, page); HttpGet get = new HttpGet(link); page++; CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig( RequestConfig.custom().setConnectTimeout(20000).build()).build(); try { CloseableHttpResponse resp = client.execute(get); if (resp.getStatusLine().getStatusCode() < HttpStatus.SC_MULTIPLE_CHOICES) { InputStream content = resp.getEntity().getContent(); List<Ad> items = parse(content, crawler); if (items == null || items.size() == 0) { break; } insertedCount += compareAndStoreItems(items, now); } else { break; } } catch (IOException | CrawlerException e) { logger.warn(e.getMessage(), e); Metadata md = new Metadata("Exception during crawl: " + e.getMessage()); storage.updateMetadata(md); break; } } logger.info("finished parsing ad entries!"); } Metadata md = new Metadata(String.format("Added %s new entries. %s crawlers have been used", insertedCount, crawlerCount)); storage.updateMetadata(md); } catch (RuntimeException | InterruptedException e) { logger.warn(e.getMessage(), e); Metadata md = new Metadata("Exception during crawl: " + e.getMessage()); storage.updateMetadata(md); } } }, 0, 1000 * 60 * 60 * crawlPeriod); }
From source file:edu.mayo.cts2.framework.plugin.service.bprdf.dao.id.DefaultIdService.java
public void afterPropertiesSet() throws Exception { this.cacheClearingTimer.scheduleAtFixedRate(new TimerTask() { @Override/* w ww . j av a 2 s . c om*/ public void run() { try { cacheBuilding = true; buildCache(); } finally { cacheBuilding = false; } } }, 0, ONE_HOUR); }
From source file:edu.iu.dymoro.Scheduler.java
public void schedule(List<Partition<S>>[] hMap) { for (int i = 0; i < numRowSplits; i++) { freeRow[numFreeRows++] = i;// w ww . j a v a 2 s . c om } for (int i = 0; i < numColSplits; i++) { freeCol[numFreeCols++] = i; } while (numFreeRows > 0 && numFreeCols > 0) { RowColSplit<D, S> split = new RowColSplit<>(); int rowIndex = random.nextInt(numFreeRows); int colIndex = random.nextInt(numFreeCols); split.row = freeRow[rowIndex]; split.col = freeCol[colIndex]; split.rData = vWHMap[split.row]; split.cData = hMap[split.col]; splitMap[split.row][split.col]++; rowCount[split.row]++; colCount[split.col]++; freeRow[rowIndex] = freeRow[--numFreeRows]; freeCol[colIndex] = freeCol[--numFreeCols]; compute.submit(split); } isRunning.set(true); TimerTask timerTask = new TimerTask() { @Override public void run() { isRunning.set(false); } }; timer.schedule(timerTask, time); while (compute.hasOutput()) { RowColSplit<D, S> split = compute.waitForOutput(); int freeRowID = -1; if (rowCount[split.row] < numRowLimit) { freeRowID = split.row; } int freeColID = -1; if (colCount[split.col] < numColLimit) { freeColID = split.col; } numItemsTrained += split.numItems; split = null; if (isRunning.get()) { // Find a matched col for the last row if (freeRowID != -1) { for (int i = 0; i < numFreeCols; i++) { if (splitMap[freeRowID][freeCol[i]] == 0) { split = new RowColSplit<>(); split.row = freeRowID; split.col = freeCol[i]; split.rData = vWHMap[split.row]; split.cData = hMap[split.col]; split.numItems = 0L; splitMap[split.row][split.col]++; rowCount[split.row]++; colCount[split.col]++; freeCol[i] = freeCol[--numFreeCols]; freeRowID = -1; compute.submit(split); break; } } } // Find a matched row for the last col if (freeColID != -1) { for (int i = 0; i < numFreeRows; i++) { if (splitMap[freeRow[i]][freeColID] == 0) { split = new RowColSplit<>(); split.row = freeRow[i]; split.col = freeColID; split.rData = vWHMap[split.row]; split.cData = hMap[split.col]; split.numItems = 0L; splitMap[split.row][split.col]++; rowCount[split.row]++; colCount[split.col]++; freeRow[i] = freeRow[--numFreeRows]; freeColID = -1; compute.submit(split); break; } } } if (freeRowID != -1) { freeRow[numFreeRows++] = freeRowID; } if (freeColID != -1) { freeCol[numFreeCols++] = freeColID; } } else { break; } } timerTask.cancel(); clean(); compute.pauseNow(); while (compute.hasOutput()) { numItemsTrained += compute.waitForOutput().numItems; } compute.cleanInputQueue(); compute.start(); }
From source file:eu.esdihumboldt.hale.io.wfs.ui.capabilities.WFSCapabilitiesFieldEditor.java
/** * Schedule the validation//from ww w. j av a2 s . c o m */ protected void scheduleValidation() { final Display display = Display.getCurrent(); synchronized (this) { if (timer != null) { timer.cancel(); } // invalidate invalidate(); // schedule validation timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { display.syncExec(new Runnable() { @Override public void run() { BusyIndicator.showWhile(display, new Runnable() { @Override public void run() { refreshValidState(); } }); } }); } }, MODIFY_VALIDATE_DELAY); } }
From source file:com.lfv.yada.net.server.ServerNetworkManager.java
public void start() { // Start up modules transactionManager.startModule();/*from w ww . j a v a 2s . co m*/ sender.startModule(); receiver.startModule(); // Add terminal timeout task timer.schedule(new TimerTask() { public void run() { long currentTime = System.currentTimeMillis(); Collection<ServerTerminal> terminals = bundle.getTerminalCollection(); Iterator<ServerTerminal> iter = terminals.iterator(); while (iter.hasNext()) { ServerTerminal terminal = iter.next(); long pingTime = terminal.getPingTime(); // If terminal is logged in.. if (pingTime > 0) { // If terminal has timed out.. if ((currentTime - pingTime) > NOPING_TIMEOUT) { // Reset terminal log.warn( "Terminal " + terminal.getId() + " has been idle for too long, going offline!"); resetTerminal(terminal, true); possibleConnectionProblem = checkAllTerminals(); } } } } }, TIMEOUT_CHECK_PERIOD, TIMEOUT_CHECK_PERIOD); started = true; possibleConnectionProblem = false; }
From source file:com.lib.DstabiProvider.java
private void startCecurityTimer() { Log.d(TAG, "zapinam timer"); securityTimer = new Timer(); securityTimer.schedule(new TimerTask() { @Override// w w w . j ava 2 s .c o m public void run() { TimerMethod(); } }, 7000, 7000); }
From source file:com.haulmont.cuba.core.app.ServerInfo.java
@Override public void applicationStarted() { if (!globalConfig.getTestMode()) { infoUpdateTimer = new Timer(true); infoUpdateTimer.schedule(new TimerTask() { @Override//from www. j a v a 2s. c o m public void run() { Thread.currentThread().setName("ServerInfoTimer"); if (AppContext.isStarted()) { updateCurrentServer(); } } }, 30000, 60000); } }