List of usage examples for java.util Timer Timer
public Timer(String name, boolean isDaemon)
From source file:net.sf.janos.Janos.java
public void run() { Display.setAppName("Janos"); final SonosController controller = SonosController.getInstance(); try {//from w ww . ja va2s. 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:com.googlecode.ehcache.annotations.RefreshingSelfPopulatingCache.java
public RefreshingSelfPopulatingCache(Ehcache cache, CacheEntryFactory cacheEntryFactory, TaskSchedulerAdapter scheduler, TaskExecutor executer, long refreshInterval) { super(cache, cacheEntryFactory); final Timer timer; if (scheduler == null) { timer = new Timer(cache.getName() + " Cache Refresh Timer", true); this.scheduler = new TimerTaskSchedulerAdapter(timer); } else {//from w ww .j a v a 2 s.com timer = null; this.scheduler = scheduler; } this.executer = executer; this.refreshInterval = refreshInterval; this.scheduleRefreshTask(); //Register a listener with the cache manager to make sure we clear out our timer thread cleanly this.getCacheManager().setCacheManagerEventListener(new CacheManagerEventListener() { public void notifyCacheRemoved(String cacheName) { } public void notifyCacheAdded(String cacheName) { } public void init() throws CacheException { } public Status getStatus() { return null; } public void dispose() throws CacheException { if (timer != null) { timer.cancel(); } } }); }
From source file:com.sidekickApp.PusherClass.java
private void startDecayTimer() { log("startDecayTimer()"); decayTimer = new Timer("decayTimer", true); long initialDelay = 0; long interval = 250; decayTimer.scheduleAtFixedRate(new TimerTask() { public void run() { // calculate decay interest = interest * decayFactor; if (interest > 100) { interest = 100;//from w w w. j a v a 2s . c om } if (interest < 0.1) { interest = 0; } log("Pusher: interest = " + interest); Intent i = new Intent(); int interestI = (int) interest; i.putExtra("com.sidekickApp.interest", interestI); i.setAction(AppState.SIDECAR_INTEREST); main.sendBroadcast(i); } }, initialDelay, interval); }
From source file:com.honnix.yaacs.auth.SessionManager.java
public SessionManager() { super();// w ww.j av a 2 s.co m sessionList = new ArrayList<Session>(ACPropertiesConstant.MAX_SESSION_NUM / 2); sessionCleaner = new SessionCleaner(); timer = new Timer("SessionCleaner", true); }
From source file:edu.wisc.nexus.auth.gidm.config.AbstractRefreshingFileLoader.java
/** * @param timerName Name of the timer to create */// w ww . j a v a 2 s.c om public AbstractRefreshingFileLoader(String timerName) { final String timerFullName = timerName + ".RefreshTimer"; this.configurationSaveTimer = new Timer(timerFullName, true); }
From source file:com.honnix.yaacs.admin.lifecycle.Lifecycle.java
private Lifecycle() throws ACException { super();//from w w w. ja va2s .c om acServer = new ACServerImpl(); lifeCycleChecker = new LifecycleChecker(); timer = new Timer("LifeCycleChecker", true); mainThread = Thread.currentThread(); }
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. ja va 2s. 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:com.tc.server.UpdateCheckAction.java
public static void start(int periodDays, long maxOffheap) { UpdateCheckAction action = new UpdateCheckAction(periodDays, maxOffheap); new Timer("Update Checker", true).schedule(action, 0, action.getCheckPeriodMillis()); }
From source file:com.lfv.yada.net.server.ServerNetworkManager.java
public ServerNetworkManager(int port, ServerBundle bundle, ServerTranslator translator) throws SocketException { // Create a logger for this class log = LogFactory.getLog(getClass()); log.debug("Creating server at port " + port); this.bundle = bundle; this.translator = translator; // The the socket to be used for sending and receiving packets DatagramSocket socket = new DatagramSocket(port); // Create a receiver and a sender receiver = new ServerPacketReceiver(socket, bundle); sender = new ServerPacketSender(socket); // Create a transaction mananger transactionManager = new TransactionManager(sender); receiver.setControlPacketDispatcher(transactionManager); receiver.setSendPacketDispatcher(sender); // Create a timer for handling terminal timeout timer = new Timer("Snetworkmanager", true); // Initialize packet pool PacketPool.getPool();/*from ww w. ja v a 2s .c o m*/ // Setup request handlers transactionManager.setRequestHandler(Packet.PING, new PingRequestPacketHandler()); transactionManager.setRequestHandler(Packet.UPDATE, new UpdateRequestPacketHandler()); transactionManager.setRequestHandler(Packet.INITIATE, new InitiateRequestPacketHandler()); }
From source file:gridool.metrics.GridNodeMetricsProvider.java
void start() throws GridException { registerMBeans(localMetrics);//w ww . ja va 2s .c o m MetricsCollector collectorTask = new MetricsCollector(localMetrics, metricsHistories); Timer timer = new Timer("gridool#MetricsCollector", true); timer.scheduleAtFixedRate(collectorTask, 1000, collectInterval); this.metricsCollector = collectorTask; this.timer = timer; }