List of usage examples for java.util Timer schedule
public void schedule(TimerTask task, Date firstTime, long period)
From source file:fr.calamus.common.db.core.DbAccessFactory.java
private static void launchInstancesObserver() { /*Thread run = new Thread() { @Override//ww w. ja v a 2s . co m public void run() { while (true) { try { Thread.currentThread().wait(10000); synchronized (instances) { long now = System.currentTimeMillis(); List<String> toRemove = new ArrayList<>(); for (String id : instances.keySet()) { AdeDbFactory db = instances.get(id); if (db == null || now > db.lastUsedTime() + db.adeTimeOut()) { toRemove.add(id); } } log.debug("removing " + toRemove.size() + " instance(s)"); for (String id : toRemove) { instances.remove(id); } } } catch (InterruptedException ex) { log.warn(ex); } } } }; run.start();*/ Timer timer = new Timer("DbAccessFactory-instancesRemover", true); TimerTask task = new TimerTask() { @Override public void run() { synchronized (instances) { long now = System.currentTimeMillis(); List<String> toRemove = new ArrayList<>(); for (String id : instances.keySet()) { DbAccess db = instances.get(id); if (id != null && (db == null || now > db.lastUsedTime() + timeOut())) { toRemove.add(id); } } for (String id : toRemove) { instances.remove(id); } if (toRemove.size() > 0) log.debug("removed " + toRemove.size() + " instance(s); remaining " + instances.size()); } } }; timer.schedule(task, 30000, 10000); }
From source file:org.sample.TimeController.java
@RequestMapping(method = RequestMethod.GET, value = { "/tick" }) public ModelAndView get() throws Exception { Connection connection = jmsFactory.createConnection(); Session jmsSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); SecureRandom srandom = new SecureRandom(); String rand = new BigInteger(176, srandom).toString(32); String q = Long.toString(System.currentTimeMillis()) + "-" + rand; Destination destination = jmsSession.createQueue(q); Timer timer = new Timer(); long delay = 1 * 1000; timer.schedule(new TickTask(jmsSession, destination), 0, delay); ModelAndView mav = new ModelAndView("client"); mav.addObject("queue", destination.toString()); return mav;//from w w w. jav a2 s . com }
From source file:org.exist.netedit.Task.java
/** * Execute task: dowload file, store desrioption, * then file changes listener and open one * in desktop application. /*from www . jav a 2s . co m*/ */ public void execute() { try { tmp = netEdit.download(downloadFrom); store(); Listener listener = new Listener(this, netEdit); Timer timer = new Timer(); timer.schedule(listener, NetEditApplet.PERIOD, NetEditApplet.PERIOD); netEdit.open(tmp); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:net.oneandone.stool.overview.config.OverviewConfiguration.java
@Bean public Timer autoRefresh() throws IOException { Timer timer; timer = new Timer("Refresh"); timer.schedule(new PrepareRefresh(session()), 20000, 60000); return timer; }
From source file:com.fatelon.partyphotobooth.kiosk.KioskService.java
/** * Starts a timer to launch and relaunch the {@link KioskActivity} in order to keep it in foreground until Kiosk * mode is disabled./*from w w w.j av a 2s. c om*/ * * @param context the {@link Context}. */ private void startKioskLauncher(final Context context) { final KioskModeHelper kioskModeHelper = new KioskModeHelper(context); final Intent intent = new Intent(context, KioskActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Start timer to launch and relaunch the KioskActivity. final Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { if (kioskModeHelper.isEnabled()) { if (!KioskActivity.sIsInForeground) { // Send Intent to start KioskActivity. startActivity(intent); } } else { // Stop the timer and the KioskService. timer.cancel(); stopSelf(); } } }, 0, KIOSK_ACTIVITY_RELAUNCH_PERIOD); }
From source file:org.sonar.server.benchmark.SourceDbBenchmarkTest.java
private void scrollRows() throws SQLException { LOGGER.info("Scroll table FILE_SOURCES"); DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis()); Connection connection = dbTester.openConnection(); AtomicLong counter = new AtomicLong(); ProgressTask progress = new ProgressTask(LOGGER, "source file", counter); Timer timer = new Timer("SourceDbScroll"); timer.schedule(progress, ProgressTask.PERIOD_MS, ProgressTask.PERIOD_MS); try {/*from www .j a v a 2 s . co m*/ long start = System.currentTimeMillis(); SourceLineResultSetIterator it = SourceLineResultSetIterator.create(dbClient, connection, 0L); while (it.hasNext()) { SourceLineResultSetIterator.SourceFile row = it.next(); assertThat(row.getLines().size()).isEqualTo(3220); assertThat(row.getFileUuid()).isNotEmpty(); counter.incrementAndGet(); } long end = System.currentTimeMillis(); long period = end - start; long throughputPerSecond = 1000L * counter.get() / period; LOGGER.info(String.format("%d FILE_SOURCES rows scrolled in %d ms (%d rows/second)", counter.get(), period, throughputPerSecond)); } finally { DbUtils.closeQuietly(connection); timer.cancel(); } }
From source file:edu.mayo.cts2.framework.plugin.service.lexevs.security.msso.RestMssoUserValidator.java
protected void scheduleflushCache() { TimerTask flushTask = new TimerTask() { @Override//from ww w . j a v a 2s. c o m public void run() { synchronized (mutex) { tokenCache.clear(); } } }; Timer timer = new Timer(); int minutesInMillis = FLUSH_PERIOD_MINUTES * 60 * 1000; timer.schedule(flushTask, 0, minutesInMillis); }
From source file:esg.node.components.monitoring.ESGMonitor.java
private void startMonitoring() { log.trace("launching system monitor timer"); long delay = Long.parseLong(props.getProperty("monitor.initialDelay")); long period = Long.parseLong(props.getProperty("monitor.period")); log.trace("monitoring delay: " + delay + " sec"); log.trace("monitoring period: " + period + " sec"); Timer timer = new Timer(); timer.schedule(new TimerTask() { public final void run() { //log.trace("Checking for new node information... [busy? "+ESGMonitor.this.isBusy+"]"); if (!ESGMonitor.this.isBusy) { ESGMonitor.this.isBusy = true; if (fetchNodeInfo()) { //TODO monitorDAO.markLastCompletionTime(); }//from w w w . ja v a2s .c o m ESGMonitor.this.isBusy = false; } } }, delay * 1000, period * 1000); }
From source file:org.wso2.carbon.identity.user.store.ws.internal.WSUserStoreDSComponent.java
private void scheduleCleanupTask() { Timer time = new Timer(); CleanupSchedulerTask cleanupSchedulerTask = new CleanupSchedulerTask(); time.schedule(cleanupSchedulerTask, 0, 5 * 60 * 60 * 1000); }
From source file:edu.ucsb.cs.cs185.inspirante.SplashScreenActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash_screen); inflateBackgroundPicList();//from w w w . j ava 2 s . c o m background = (ImageView) findViewById(R.id.splash_image); ShimmerFrameLayout container = (ShimmerFrameLayout) findViewById(R.id.shimmer_view_container); container.setDuration(SHIMMER_DURATION); container.startShimmerAnimation(); Timer changeBackgroundTimer = new Timer(); changeBackgroundTimer.schedule(new TimerTask() { @Override public void run() { updateBackground(); } }, 0, 3000); final Button signUpButton = (Button) findViewById(R.id.sign_up); signUpButton.getBackground().setColorFilter( ContextCompat.getColor(getApplicationContext(), R.color.splashWhiteTransparent), PorterDuff.Mode.MULTIPLY); final Button logInButton = (Button) findViewById(R.id.log_in); logInButton.getBackground().setColorFilter( ContextCompat.getColor(getApplicationContext(), R.color.splashWhiteTransparent), PorterDuff.Mode.MULTIPLY); signUpButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent signUpIntent = new Intent(SplashScreenActivity.this, LoginSignupActivity.class); signUpIntent.putExtra("TYPE", "SIGN_UP"); SplashScreenActivity.this.startActivity(signUpIntent); SplashScreenActivity.this.finish(); signUpButton.getBackground().setColorFilter( ContextCompat.getColor(getApplicationContext(), R.color.MyPink), PorterDuff.Mode.MULTIPLY); } }); logInButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent logInIntent = new Intent(SplashScreenActivity.this, LoginSignupActivity.class); logInIntent.putExtra("TYPE", "LOG_IN"); SplashScreenActivity.this.startActivity(logInIntent); SplashScreenActivity.this.finish(); logInButton.getBackground().setColorFilter( ContextCompat.getColor(getApplicationContext(), R.color.MyPink), PorterDuff.Mode.MULTIPLY); } }); }