List of usage examples for java.util Timer schedule
public void schedule(TimerTask task, Date time)
From source file:com.gnizr.core.robot.rss.TestCrawlRssFeed.java
public void testRun() throws Exception { Timer timer = new Timer(); timer.schedule(crawlRssFeed, 0); crawlRssFeed.awaitAndShutdown(60, TimeUnit.SECONDS); Folder folder66 = folderManager.getUserFolder(new User(2), "latest news"); Folder folder67 = folderManager.getUserFolder(new User(2), "news2"); assertTrue(folder66.getSize() > 0); assertEquals(folder66.getSize(), folder67.getSize()); Folder importFolder = folderManager.getUserFolder(new User(2), FolderManager.IMPORTED_BOOKMARKS_LABEL); assertTrue(importFolder.getSize() > 0); Folder folder69 = folderManager.getUserFolder(new User(2), "georss data"); assertTrue(folder69.getSize() > 0); DaoResult<Bookmark> result2 = folderManager.pageFolderContent(new User(2), "georss data", 0, 1); Bookmark bm = result2.getResult().get(0); List<PointMarker> markers = bookmarkManager.getPointMarkers(bm); assertTrue(markers.size() > 0);// ww w . ja v a 2 s.c om }
From source file:com.cnaude.purpleirc.Utilities.UpdateChecker.java
public void asyncUpdateCheck(final CommandSender sender, final String mode) { Timer t = new Timer(); t.schedule(new TimerTask() { @Override/*from w ww . j av a2s. c om*/ public void run() { if (plugin.isUpdateCheckerEnabled()) { updateCheck(sender, mode); } } }, 0); }
From source file:br.com.grupofortress.controller.Agendamentos.java
public void terceiraTarefa() { Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, 9); c.set(Calendar.MINUTE, 40);//from w ww. j a va 2 s . c o m c.set(Calendar.SECOND, 0); Date time = c.getTime(); final Timer t = new Timer(); t.schedule(new TimerTask() { @Override public void run() { System.out.println( "Enviando email _________________________________________________________________ \n"); ClientesDao cli = new ClientesDao(); int qtdSemComunicacao = 0; String msg = "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"3\" border=\"0\" bgcolor=\"#CCCCCC\">\n" + " <tr>\n" + " <td bgcolor=\"#CC0000\"><font size=1 face=\"verdana, arial, helvetica\" color=\"#FFFFFF\"><b>Clientes Sem Comunicao</b></font></td>\n" + " </tr>\n" + " <tr>\n" + " <td bgcolor=\"#F5ECB9\"><table width=\"95%\" cellspacing=\"1\" cellpadding=\"1\" border=\"0\" align=\"center\">\n" + " <tr>\n" + " <td valign=top><font face=\"verdana, arial, helvetica\" size=1><strong>Cdigo</strong></font></td>\n" + " <td><font face=\"verdana, arial, helvetica\" size=1><strong>Nome</strong></font></td>\n" + " <td><font size=\"1\" face=\"verdana, arial, helvetica\"><strong>Ultimo Evento Recebido</strong></font></td>"; for (Cliente cliente : cli.getClientesSemComunicacao("")) { qtdSemComunicacao++; msg = msg + "<tr>" + " <td valign=top><font face=\"verdana, arial, helvetica\" size=1>" + cliente.getCli_codigo() + "</font></td>\n" + " <td><font face=\"verdana, arial, helvetica\" size=1>" + cliente.getCli_nome() + "</font></td>\n" + " <td><font size=\"1\" face=\"verdana, arial, helvetica\">" + Universal.getInstance().calendarToString(cliente.getCli_ultima_comunicacao()) + "</font></td>" + "</tr>"; } msg = msg + " </table></td>\n" + " </tr>\n" + " <tr>\n" + " <td bgcolor=\"#CCCCCC\"><font size=1 face=\"verdana, arial, helvetica\"><b>Total de Clientes sem Comunicao: " + qtdSemComunicacao + "</b></font></td>\n" + "</tr>" + "</table> "; CommonsMail enviaEmail = new CommonsMail(); try { enviaEmail.enviaEmailFormatoHtml(formatString(msg)); } catch (EmailException ex) { Logger.getLogger(GerarTarefasAgendadas.class.getName()).log(Level.SEVERE, null, ex); } catch (MalformedURLException ex) { Logger.getLogger(GerarTarefasAgendadas.class.getName()).log(Level.SEVERE, null, ex); } } }, time); }
From source file:com.umanji.umanjiapp.gcm.GcmRegistrationIntentService.java
private void initGcm(IntentService service) { Log.d(TAG, "initGcm"); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); try {//from w ww .j av a 2s .com InstanceID instanceID = InstanceID.getInstance(service); final String token = instanceID.getToken(getString(R.string.gcm_sender_id), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { sendRegistrationToServer(token); } }, 2000); subscribeTopics(token); sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, true).apply(); } catch (Exception e) { Log.d(TAG, "Failed to complete token refresh", e); sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false).apply(); } Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE); LocalBroadcastManager.getInstance(service).sendBroadcast(registrationComplete); }
From source file:com.mydlp.ui.service.LicenseServiceImpl.java
protected void scheduleLicenseCheck(final int delay) { Timer timer = new Timer(); timer.schedule(new TimerTask() { public void run() { scheduleLicenseCheckFun();//from w ww . j a v a 2s . com if (!licenseAcquired && retryCounter > 0) { retryCounter--; scheduleLicenseCheck(delay); } } }, delay); }
From source file:org.eclipse.swordfish.core.util.SimpleClient.java
public void start() { checkConstraints();/*from w ww. j av a2 s.c o m*/ 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:org.durka.hallmonitor.ViewCoverProximityService.java
@Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) { Log.d(LOG_TAG + ".onSC", "Proximity sensor changed, value=" + event.values[0]); proximity(event.values[0]);/* www. j ava 2 s . com*/ // improve reliability by refiring the event 200ms afterwards final float val = event.values[0]; Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { proximity(val); } }, 200); timer.schedule(new TimerTask() { @Override public void run() { proximity(val); } }, 500); } }
From source file:org.apache.hadoop.yarn.util.AdHocLogDumper.java
public void dumpLogs(String level, int timePeriod) throws YarnRuntimeException, IOException { synchronized (lock) { if (logFlag) { LOG.info("Attempt to dump logs when appender is already running"); throw new YarnRuntimeException("Appender is already dumping logs"); }/*w w w .ja v a 2 s . c o m*/ Level targetLevel = Level.toLevel(level); Log log = LogFactory.getLog(name); appenderLevels.clear(); if (log instanceof Log4JLogger) { Logger packageLogger = ((Log4JLogger) log).getLogger(); currentLogLevel = packageLogger.getLevel(); Level currentEffectiveLevel = packageLogger.getEffectiveLevel(); // make sure we can create the appender first Layout layout = new PatternLayout("%d{ISO8601} %p %c: %m%n"); FileAppender fApp; File file = new File(System.getProperty("yarn.log.dir"), targetFilename); try { fApp = new FileAppender(layout, file.getAbsolutePath(), false); } catch (IOException ie) { LOG.warn("Error creating file, can't dump logs to " + file.getAbsolutePath(), ie); throw ie; } fApp.setName(AdHocLogDumper.AD_HOC_DUMPER_APPENDER); fApp.setThreshold(targetLevel); // get current threshold of all appenders and set it to the effective // level for (Enumeration appenders = Logger.getRootLogger().getAllAppenders(); appenders .hasMoreElements();) { Object obj = appenders.nextElement(); if (obj instanceof AppenderSkeleton) { AppenderSkeleton appender = (AppenderSkeleton) obj; appenderLevels.put(appender.getName(), appender.getThreshold()); appender.setThreshold(currentEffectiveLevel); } } packageLogger.addAppender(fApp); LOG.info("Dumping adhoc logs for " + name + " to " + file.getAbsolutePath() + " for " + timePeriod + " milliseconds"); packageLogger.setLevel(targetLevel); logFlag = true; TimerTask restoreLogLevel = new RestoreLogLevel(); Timer restoreLogLevelTimer = new Timer(); restoreLogLevelTimer.schedule(restoreLogLevel, timePeriod); } } }
From source file:gov.nih.nci.caxchange.messaging.AdverseEventLoadTest.java
/** * Testcase for sending the messages//ww w. j a va 2 s . co m * * @throws InterruptedException - InterruptedException */ @Test public void sendAdverseEventMessage() throws InterruptedException { final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(currDt.getTime() + 5000); currDt = calendar.getTime(); final Timer timer = new Timer(); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); es.awaitTermination(3, TimeUnit.MINUTES); }
From source file:gov.nih.nci.caxchange.messaging.RegistrationLoadTest.java
/** * Testcase for sending the messages/*from w w w . j a v a2s . c o m*/ * * @throws InterruptedException - InterruptedException */ @Test public void sendRegistrationMessage() throws InterruptedException { final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(currDt.getTime() + 5000); currDt = calendar.getTime(); final Timer timer = new Timer(); timer.schedule(getTimerTask(0), currDt); timer.schedule(getTimerTask(1), currDt); timer.schedule(getTimerTask(2), currDt); timer.schedule(getTimerTask(3), currDt); timer.schedule(getTimerTask(4), currDt); timer.schedule(getTimerTask(5), currDt); timer.schedule(getTimerTask(6), currDt); timer.schedule(getTimerTask(7), currDt); timer.schedule(getTimerTask(8), currDt); timer.schedule(getTimerTask(9), currDt); timer.schedule(getTimerTask(10), currDt); timer.schedule(getTimerTask(11), currDt); timer.schedule(getTimerTask(12), currDt); timer.schedule(getTimerTask(13), currDt); timer.schedule(getTimerTask(14), currDt); timer.schedule(getTimerTask(15), currDt); timer.schedule(getTimerTask(16), currDt); timer.schedule(getTimerTask(17), currDt); timer.schedule(getTimerTask(18), currDt); timer.schedule(getTimerTask(19), currDt); es.awaitTermination(3, TimeUnit.MINUTES); }