List of usage examples for java.util Timer Timer
public Timer(String name)
From source file:org.fusesource.cloudmix.agent.AgentPoller.java
public void start() throws Exception { timer = new Timer(true); timer.scheduleAtFixedRate(new TimerTask() { public void run() { agentPoll();//w ww . j a v a 2s . co m } }, initialPollingDelay, pollingPeriod); }
From source file:com.clustercontrol.accesscontrol.util.SessionTimer.java
/** * ??//ww w .j a v a 2s .co m * * @param inverval () */ public void start(final int interval) { // ??????? if (m_timer == null && interval > 0) { // ? m_timer = new Timer(true); final ServiceContext context = ContextProvider.getContext(); m_log.debug("SessionTimer start"); // m_timer.schedule(new TimerTask() { @Override public void run() { m_log.trace("SessionTimer start at Date : " + (new Date()).toString()); ContextProvider.releaseContextHolder(); ContextProvider.setContext(context); ClientSession.doCheck(); } }, 1000, (long) interval * 60 * 1000); } }
From source file:com.gmind7.bakery.websocket.SnakeTimer.java
public static void startTimer() { gameTimer = new Timer(SnakeTimer.class.getSimpleName() + " Timer"); gameTimer.scheduleAtFixedRate(new TimerTask() { @Override/* w ww . j a v a2 s.c o m*/ public void run() { try { tick(); } catch (Throwable e) { log.error("Caught to prevent timer from shutting down", e); } } }, TICK_DELAY, TICK_DELAY); }
From source file:disko.DU.java
public static synchronized Timer getTimer() { if (globalTimer == null) globalTimer = new Timer(true); return globalTimer; }
From source file:de.nava.informa.utils.ChannelRegistry.java
/** * Constructor for a new ChannelRegistry object, the new items found by * scanning the are created using the given <code>builder</code>. * * @param builder The ChannelBuilderIF to use for creating news items. *//* w ww . j a v a 2s .c o m*/ public ChannelRegistry(ChannelBuilderIF builder) { this.builder = builder; this.channels = builder.createChannelGroup("Default"); // start a new timer 'daemon' which controls updating tasks updateDaemon = new Timer(true); updateTasks = new HashMap<>(); channelInfos = new HashMap<>(); acceptNrOfErrors = DEFAULT_ACCEPT_NR_ERRORS; }
From source file:name.nirav.mp.service.analytics.EntityExtractionService.java
public EntityExtractionService(OpenCalaisConfig config, PredictionDB db) { this.config = config; this.calaisConfig = new CalaisConfig(); this.calaisConfig.set(CalaisConfig.ConnParam.READ_TIMEOUT, config.readTimeout); this.calaisConfig.set(CalaisConfig.ConnParam.CONNECT_TIMEOUT, config.readTimeout); this.db = db; this.client = new CalaisRestClient(config.licenseKey); this.rateLimiter = RateLimiter.create(4); Timer timer = new Timer("Calais-ban-reset"); timer.scheduleAtFixedRate(new TimerTask() { public void run() { LocalDateTime now = LocalDateTime.now(); if (now.getHour() >= 23) { LOG.info("It is close to midnight {}, resetting callCount", now.getHour()); callCount = 0;/*from w w w .j a v a 2 s . co m*/ } } }, 1000, TimeUnit.MINUTES.toMillis(30)); }
From source file:org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilterTests.java
public void testStartsThreadAtStartup() throws Exception { final MethodFlag scheduleMethodFlag = new MethodFlag(); final Cas20ProxyReceivingTicketValidationFilter filter = newCas20ProxyReceivingTicketValidationFilter(); final Timer timer = new Timer(true) { public void schedule(TimerTask task, long delay, long period) { scheduleMethodFlag.setCalled(); }// ww w. ja va 2 s.c o m }; filter.setMillisBetweenCleanUps(1); filter.setProxyGrantingTicketStorage(storage); filter.setTimer(timer); filter.setTimerTask(defaultTimerTask); filter.init(); assertTrue(scheduleMethodFlag.wasCalled()); }
From source file:ch.rasc.s4ws.snake.SnakeTimer.java
public static void startTimer() { gameTimer = new Timer(SnakeTimer.class.getSimpleName() + " Timer"); gameTimer.scheduleAtFixedRate(new TimerTask() { @Override/*from w w w . jav a2s . c om*/ public void run() { try { tick(); } catch (RuntimeException e) { log.error("Caught to prevent timer from shutting down", e); } } }, TICK_DELAY, TICK_DELAY); }
From source file:price.calculation.gateway.service.impl.PriceRequesterServiceImpl.java
@Override public Response calulatePrice(Product product) { res = null;/*www . j av a 2 s . c om*/ final HttpClient client = new DefaultHttpClient(); final HttpPost post = new HttpPost(url); try { post.setHeader("Content-type", "application/json"); post.setEntity(new StringEntity(product.toJson())); } catch (UnsupportedEncodingException ex) { res = new Response("Invalid encoding", 400); Logger.getLogger(PriceRequesterServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } TimerTask calculationTask = new TimerTask() { @Override public void run() { if (post != null) { res = new CalculationTimedOut(); post.abort(); } } }; new Timer(true).schedule(calculationTask, timeout * 1000); try { HttpResponse httpResponse = client.execute(post); String jsonResp = EntityUtils.toString(httpResponse.getEntity()); res = CalculatedPrice.fromJson(jsonResp); } catch (IOException ex) { res = new Response("Service Unavailable", 503); Logger.getLogger(PriceRequesterServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } return res; }
From source file:com.vmware.identity.session.TomcatAccessLogCleaner.java
/** * Perform clean up of the tomcat access log files */// ww w .j a v a 2 s .com public void startLogCleaningProcess(File accessLogDirectory) { logger.info("Cleaning up tomcat access log files under : {}", accessLogDirectory.getAbsolutePath()); Timer timer = new Timer(IS_DAEMON); AccessLogCleanerTask tomcatAccessLogCleaner = new AccessLogCleanerTask(accessLogDirectory); logger.info("Starting to schedule the log clean up tasks.."); timer.scheduleAtFixedRate(tomcatAccessLogCleaner, 0, TIMER_TASK_DELAY_IN_MILLIS); }