List of usage examples for java.util TimerTask TimerTask
protected TimerTask()
From source file:Chopstick.java
public Timeout(int delay, final String msg) { super(true); // Daemon thread schedule(new TimerTask() { public void run() { System.out.println(msg); System.exit(0);/*from w w w. j a v a2s . c o m*/ } }, delay); }
From source file:com.netflix.http4.ConnectionPoolCleaner.java
public void initTask() { if (enableConnectionPoolCleanerTask) { timer = new Timer(name + "-ConnectionPoolCleanerThread", true); timer.schedule(new TimerTask() { public void run() { try { cleanupConnections(); } catch (Throwable e) { logger.error("Exception in ConnectionPoolCleanerThread", e); //e.printStackTrace(); }/*from w w w. j av a 2 s .c o m*/ } }, connectionCleanerTimerDelay, connectionCleanerRepeatInterval); logger.info("Initializing ConnectionPoolCleaner for NFHttpClient:" + name); // Add it to the shutdown hook Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { logger.info("Stopping the ConnectionPoolCleaner Update Task"); timer.cancel(); } })); } }
From source file:be.fgov.kszbcss.rhq.websphere.connector.notification.NotificationListenerManager.java
public NotificationListenerRegistration addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback, boolean extended) { NotificationListenerRegistration registration = new NotificationListenerRegistration(this, name, listener, filter, handback, extended); registration.update(adminClient);/*w w w.j ava 2 s .com*/ synchronized (registrations) { registrations.add(registration); if (timer == null) { log.debug("Starting notification registration timer"); timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { updateRegistrations(); } }, 60000, 60000); } } return registration; }
From source file:burstcoin.observer.service.PoolService.java
private void startCheckPoolsTask() { timer.schedule(new TimerTask() { @Override//from w ww .j a v a 2 s.com public void run() { try { blocks = getBlocks(10 /*last 10 days*/); final Map<String, Integer> countLookup = new HashMap<>(); Map<String, Long> rewardLookup = new HashMap<>(); for (Block block : PoolService.this.blocks) { String generatorRS = block.getGeneratorRS(); Long reward = Long.valueOf(block.getBlockReward()); Long fee = Long.valueOf(block.getTotalFeeNQT()); if (!countLookup.containsKey(generatorRS)) { countLookup.put(generatorRS, 1); rewardLookup.put(generatorRS, reward + fee); } else { Integer count = countLookup.get(generatorRS) + 1; countLookup.put(generatorRS, count); Long rewards = rewardLookup.get(generatorRS) + reward + fee; rewardLookup.put(generatorRS, rewards); } } Map<String, Set<String>> rewardAssignmentLookup = new HashMap<>(); rewardAssignmentLookup.put(SOLO_KEY, new HashSet<>()); for (Block block : blocks) { if (block != null) { final String numericGeneratorAccountId = block.getGenerator(); // check if numericGeneratorAccountId is known already boolean generatorKnown = false; Iterator<Map.Entry<String, Set<String>>> iterator = rewardAssignmentLookup.entrySet() .iterator(); while (!generatorKnown && iterator.hasNext()) { generatorKnown = iterator.next().getValue().contains(numericGeneratorAccountId); } if (!generatorKnown) { RewardRecipient rewardRecipient = getRewardRecipient(numericGeneratorAccountId); final String rewardRecipientAccounId = rewardRecipient.getRewardRecipient(); if (numericGeneratorAccountId.equals(rewardRecipientAccounId)) { // solo rewardAssignmentLookup.get(SOLO_KEY).add(rewardRecipientAccounId); } else { // pool - get all reward Assignments of new found pool; rewardAssignmentLookup.put(rewardRecipientAccounId, getAccountsWithRewardRecipient(rewardRecipientAccounId)); } } } } List<PoolBean> poolBeans = onRewardAssignmentLookup(rewardAssignmentLookup); publisher.publishEvent(new PoolUpdateEvent(poolBeans)); } catch (Exception e) { LOG.error("Failed updating Pool data."); } } }, 200, ObserverProperties.getPoolRefreshInterval()); }
From source file:com.googlecode.arit.jmx.LeakDetector.java
public void afterPropertiesSet() throws Exception { timer = AccessController.doPrivileged(new PrivilegedAction<Timer>() { public Timer run() { timer = new Timer("LeakDetectorTimer"); timer.schedule(new TimerTask() { @Override/*from w ww. j av a2 s . com*/ public void run() { try { runDetection(); } catch (Throwable ex) { log.error("Leak detection failed", ex); } } }, 0, 60000); return timer; } }); }
From source file:ch.rasc.wampspring.demo.various.snake.SnakeService.java
public void startTimer() { this.gameTimer = new Timer(SnakeService.class.getSimpleName() + " Timer"); this.gameTimer.scheduleAtFixedRate(new TimerTask() { @Override/*from w ww. j a v a2s . c om*/ public void run() { tick(); } }, 100, 100); }
From source file:monitoring.tools.AppTweak.java
private void resetStream() { logger.debug("Initialising streaming"); //this.kafka.initProducer(this.params.getKafkaEndpoint()); this.kafka.initProxy(this.params.getKafkaEndpoint()); firstConnection = true;/*from w ww. j av a2 s .c o m*/ timer = new Timer(); timer.schedule(new TimerTask() { public void run() { if (firstConnection) { logger.debug("Connection established"); initTime = new Date(); firstConnection = false; } else { stamp = initTime; initTime = new Date(); try { apiCall(); } catch (IOException e) { logger.error("The API call was not correctly build"); } catch (JSONException | ParseException e) { logger.error("The response provided by the API tool was not a valid JSON object"); } } } }, 0, Integer.parseInt(params.getTimeSlot()) * 1000); }
From source file:monitoring.tools.GooglePlayAPI.java
private void resetStream() throws Exception { //this.kafka.initProducer(this.params.getKafkaEndpoint()); this.kafka.initProxy(this.params.getKafkaEndpoint()); firstConnection = true;//w w w . j av a2 s . c o m generateNewAccessToken(); timer = new Timer(); timer.schedule(new TimerTask() { public void run() { if (firstConnection) { logger.debug("Connection established"); initTime = new Date(); firstConnection = false; } else { stamp = initTime; initTime = new Date(); try { apiCall(); } catch (IOException e) { logger.debug("Invalid access token. Generating a new one"); try { generateNewAccessToken(); apiCall(); } catch (IOException e1) { logger.error("There was an unexpected error with the API call"); } } } } }, 0, Integer.parseInt(params.getTimeSlot()) * 1000); }
From source file:com.ushahidi.android.app.BackgroundService.java
/** * Starts the background service/*from w w w . j a v a 2 s . c o m*/ * * @return void */ private void startService() { Preferences.loadSettings(mContext); long period = (1 * 60000); long delay = 500; mDoTask = new TimerTask() { @Override public void run() { handler.post(new Runnable() { public void run() { // Perform a task Util.fetchReports(BackgroundService.this); showNotification(Preferences.totalReportsFetched); } }); } }; // Schedule the task. mT.scheduleAtFixedRate(mDoTask, delay, period); }
From source file:com.dangdang.config.service.zookeeper.ZookeeperConfigGroup.java
/** * ?//w w w . jav a2 s.c o m */ private void initConfigs() { client = CuratorFrameworkFactory.newClient(configProfile.getConnectStr(), configProfile.getRetryPolicy()); client.start(); client.getCuratorListenable().addListener(listener); LOGGER.debug("Loading properties for node: {}, with loading mode: {} and keys specified: {}", node, configProfile.getKeyLoadingMode(), configProfile.getKeysSpecified()); loadNode(); // Update local cache if (configLocalCache != null) { configLocalCache.saveLocalCache(this, node); } // Consistency check if (configProfile.isConsistencyCheck()) { timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { LOGGER.trace("Do consistency check for node: {}", node); loadNode(); } }, 60000L, configProfile.getConsistencyCheckRate()); } }