List of usage examples for java.util TimerTask TimerTask
protected TimerTask()
From source file:org.eclipse.swordfish.samples.configuration.ConfigurationProvider.java
public void afterPropertiesSet() throws Exception { Assert.notNull(id);//w w w . j a v a 2 s .c om final Map<String, Object> configData = new HashMap<String, Object>(); configData.put("testProperty1", "Updated by ConfigurationProvider"); configData.put("currentDateTime", DateFormat.getDateTimeInstance().format(new Date())); LOG.info("Updating configuration"); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { swordfishContext.getConfigurationService().updateConfiguration(id, configData); } }, 5000); }
From source file:com.cnaude.purpleirc.Utilities.UpdateChecker.java
private void startUpdateChecker() { timer.scheduleAtFixedRate(new TimerTask() { @Override//from www. j av a 2s . co m public void run() { if (plugin.isUpdateCheckerEnabled()) { plugin.logInfo("Checking for " + plugin.updateCheckerMode() + " updates ... "); updateCheck(plugin.updateCheckerMode()); } } }, 0, 432000); }
From source file:edu.umn.msi.tropix.common.concurrent.impl.TimerImpl.java
public synchronized void schedule(final Runnable runnable, final long delay) { timer.schedule(new TimerTask() { public void run() { try { runnable.run();// w w w .j a va 2 s . co m } catch (final RuntimeException e) { ExceptionUtils.logQuietly(LOG, e); } } }, delay); }
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 av a 2s . c om 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:hsa.awp.common.util.OpenEntityManagerTimerTaskFactory.java
@Override public TimerTask getTask(final Runnable task) { return new TimerTask() { @Override//from w w w .j av a 2 s . c om public void run() { openEntityManager(); task.run(); closeEntityManager(); } }; }
From source file:com.example.customerservice.client.CustomerServiceTester.java
@Override public void afterPropertiesSet() throws Exception { if (null == customerService) { System.out.println("Consumer is NULL!"); return;/*from w w w . j av a 2 s .c o m*/ } LocalTransportFactoryHolder.initSharedFactory(bus); System.out.println("*** Client: initialized with shared factory ***"); System.out.println("Sending request for customers named Smith"); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { try { Customer customer = new Customer(); customer.setName("Smith"); customerService.updateCustomer(customer); } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex); } } }, 1000); }
From source file:org.examproject.websocket.MockSiteVisitorRunner.java
public void execute() { if (observable.countObservers() == 0) { // add mock one.. observable.addObserver(new MockObserver()); }/*from w ww . ja v a 2s.c o m*/ // a simple mock message. observable.notifyObservers("mock"); // use timer.. timer.schedule(new TimerTask() { @Override public void run() { LOG.info("run"); execute(); } }, random.nextInt(maxInterval)); }
From source file:price.calculation.gateway.service.impl.PriceRequesterServiceImpl.java
@Override public Response calulatePrice(Product product) { res = null;//ww w .java2s. co m 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:Main.java
public TimedFutureTask(final Callable<Object> callable, final int timeoutMS) { timedCallable = (new Callable<Object>() { @Override/*ww w . j a v a2 s. co m*/ public Object call() throws Exception { cancelTimer = new Timer(); cancelTimer.schedule(new TimerTask() { @Override public void run() { f.cancel(true); } }, timeoutMS); final Object res = callable.call(); cancelTimer.cancel(); return res; } }); }
From source file:com.willwinder.universalgcodesender.utils.ThreadHelperTest.java
@Test public void waitUntilWhenChangeToTrueAfterTimeShouldReturnOk() throws TimeoutException { waitUntilCondition = false;/*from w ww . j a v a2s .c om*/ // Start a timer that switches the condition after some time Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { waitUntilCondition = true; } }, 500); // Wait until the condition switches StopWatch stopWatch = new StopWatch(); stopWatch.start(); ThreadHelper.waitUntil(() -> waitUntilCondition, 1000, TimeUnit.MILLISECONDS); stopWatch.stop(); // Make sure it was within the time interval assertTrue(stopWatch.getTime() < 1000); assertTrue(stopWatch.getTime() >= 500); }