List of usage examples for java.util TimerTask TimerTask
protected TimerTask()
From source file:ru.asmsoft.p2p.storage.MemoryNodesRepository.java
@PostConstruct public void init() { Cache<String, Node> cache = CacheBuilder.newBuilder() .expireAfterAccess(config.getHeartbeatPeriodExpired(), TimeUnit.MILLISECONDS).removalListener(this) .build();/*from w w w .j av a2s . com*/ nodes = cache.asMap(); // Initialization delay (Heartbeat period * 2) new Timer().schedule(new TimerTask() { @Override public void run() { logger.debug("NodesRepository is ready."); isInitialised = true; } }, config.getHeartbeatPeriod() * 2); }
From source file:fr.calamus.common.db.core.DbCentralFactory.java
protected static void launchInstancesObserver() { if (!instancesObserverIsLaunched) { Timer timer = new Timer("DbFactory-instancesRemover", true); TimerTask task = new TimerTask() { @Override/*ww w .jav a 2s .co m*/ public void run() { synchronized (instances) { long now = System.currentTimeMillis(); List<String> toRemove = new ArrayList<>(); for (String id : instances.keySet()) { DbCentralFactory db = instances.get(id); if (id != null && (db == null || now > db.lastUsedTime() + db.cnxTimeOut())) { toRemove.add(id); } } for (String id : toRemove) { DbCentralFactory db = instances.get(id); if (db != null) { db.close(); } instances.remove(id); } if (toRemove.size() > 0) { log.debug("removed " + toRemove.size() + " instance(s); remaining " + instances.size()); } } } }; timer.schedule(task, 30000, 10000); instancesObserverIsLaunched = true; } }
From source file:dk.netarkivet.harvester.scheduler.JobSupervisor.java
/** * <ol>//w w w . j a v a2 s . c o m * <li> Starts the rescheduling of left over jobs (in a separate thread). * <li> Starts the timer for cleaning old jobs. eg. jobs that have been run * longer than {@link HarvesterSettings#JOB_TIMEOUT_TIME}. * </ol> */ @Override public void start() { Thread thread = new Thread(new Runnable() { public void run() { rescheduleLeftOverJobs(); } }); thread.start(); timer.schedule(new TimerTask() { public void run() { cleanOldJobs(); } }, Settings.getInt(HarvesterSettings.JOB_TIMEOUT_TIME)); }
From source file:hermes.swing.SwingAppender.java
protected void append(LoggingEvent event) { if (!active || !checkEntryConditions()) { return;// w w w .ja va 2 s .com } if (event.getLoggerName().startsWith(filter)) { synchronized (cachedRows) { cachedRows.add(format.format(new Date(event.timeStamp)) + " " + event.getLevel() + " [" + event.getThreadName() + "] " + event.getLoggerName() + " " + event.getMessage()); } if (timerTask == null) { timerTask = new TimerTask() { public void run() { updateModel(); } }; timer.schedule(timerTask, updateInterval, updateInterval); } } }
From source file:net.pms.util.TempFileMgr.java
public void schedule() { TimerTask task = new TimerTask() { @Override//from w w w. jav a 2s . c om public void run() { scan(); } }; Timer t = new Timer(); t.scheduleAtFixedRate(task, 0, INTERVAL); }
From source file:net.sf.janos.Janos.java
public void run() { Display.setAppName("Janos"); final SonosController controller = SonosController.getInstance(); try {//from ww w . ja va2 s. c o m SonosControllerShell shell = new SonosControllerShell(new Display(), controller); try { Timer zonePollerTimer = new Timer("ZonePoller", true); TimerTask zonePollerTask = new TimerTask() { @Override public void run() { controller.searchForDevices(); long pollPeriod = Long.parseLong(System.getProperty("net.sf.janos.pollPeriod", "5000")); controller.purgeStaleDevices(pollPeriod * 2); } }; long pollPeriod = Long.parseLong(System.getProperty("net.sf.janos.pollPeriod", "5000")); zonePollerTimer.scheduleAtFixedRate(zonePollerTask, 0, pollPeriod); Thread.sleep(Integer.parseInt(System.getProperty("net.sf.janos.searchTime", "1000"))); } catch (NumberFormatException e) { LogFactory.getLog(Janos.class).warn("Sleep interrupted:", e); } catch (InterruptedException e) { LogFactory.getLog(Janos.class).warn("Sleep interrupted:", e); } ApplicationContext.create(controller, shell); shell.start(); } catch (Throwable t) { LOG.fatal("Error running Janos", t); } finally { // attempt to unregister from zone players controller.dispose(); } }
From source file:org.eclipse.swordfish.core.util.SimpleClient.java
public void start() { checkConstraints();// w ww. ja v a2s . com Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { try { sendRequestSynchronously(); } catch (Exception ex) { throw new RuntimeException(ex); } } }, delayBeforeSending); }
From source file:nz.co.senanque.madura.bundle.BundleManagerImpl.java
@Override public void init() { super.init(); scanServletContext();/*from w w w .j a v a 2 s . c o m*/ if (getTime() != -1) { // we have a timer so launch it now TimerTask t = new TimerTask() { @Override public void run() { scan(); } }; Timer timer = new Timer(); timer.schedule(t, m_time, m_time); } else { scan(); } }
From source file:com.mtnsat.testcode.StopWatch.java
public void running() { split = false;/* w w w. ja v a 2 s . c o m*/ if (timer == null) { timer = new Timer(true); timer.scheduleAtFixedRate(new TimerTask() { public void run() { increment(); } }, 100, 100); } }
From source file:turtlekit.viewer.StatesPerSecondCharter.java
/** * //from w ww .jav a 2 s . c o m */ private void initTimer() { stopTimer(); timer = new java.util.Timer(true); timer.scheduleAtFixedRate(new TimerTask() { private double last = 0; @Override public void run() { try { final double gvt = probe.getPropertyValue(); final double statesPerSecond = (gvt - last); if (logger != null) logger.fine("statesPerSecond =" + statesPerSecond); last = gvt; SwingUtilities.invokeLater(new Runnable() {// avoiding null pointers on the awt thread @Override public void run() { if (statesPerSecond > 0) { serie.add((int) gvt, statesPerSecond); } } }); } catch (NullPointerException e) {//ugly but avoids e when quiting } } }, 0, getRefreshRate()); }