List of usage examples for java.util Timer Timer
public Timer()
From source file:net.vicp.lylab.util.timer.LYPlan.java
public static void BeginSchedule(LYPlan plan) { if (Scheduled) return;//from ww w. ja va2 s . c o m else Scheduled = true; Timer timer = new Timer(); for (TimerJob bj : plan.getJobs()) { if (bj.getInterval() != 0) timer.schedule(bj, bj.getStartTime(), bj.getInterval()); else timer.schedule(bj, bj.getStartTime()); System.out.println("LYPlan - Load Schedule Job: " + bj.getClass().getName()); } }
From source file:jease.cms.service.Timers.java
public static void start() { stop();/* w w w . j ava 2 s .co m*/ timer = new Timer(); timer.schedule(new TimerTask() { public void run() { try { String newTimerTaskClass = Registry.getParameter(Names.JEASE_TIMER_TASK); if (StringUtils.isNotBlank(newTimerTaskClass)) { if (!StringUtils.equals(timerTaskClass, newTimerTaskClass)) { timerTaskClass = newTimerTaskClass; runnable = (Runnable) Reflections.newInstance(timerTaskClass); } if (runnable != null) { runnable.run(); } } } catch (Throwable e) { timerTaskClass = null; runnable = null; } } }, 1000, 1000); }
From source file:Main.java
/** * Creates a new timer whose associated thread has the specified name in Java 1.5. * /*from w ww . ja v a 2 s .c o m*/ * @param name the name of the associated thread * */ public static Timer createTimer(String name) { try { Constructor c = Timer.class.getConstructor(new Class[] { String.class }); return (Timer) c.newInstance(new Object[] { name }); } catch (Throwable e) { // In cany case create new Timer return new Timer(); } }
From source file:com.pureinfo.force.util.TimerUtil.java
/** * @param _sTime//ww w. j a v a 2s. c o m * must be "HH:mm" format */ public static Timer scheduleFrom(String _sTime, long _lPeriod, TimerTask _task) { Calendar nowTime = new GregorianCalendar(); Calendar firstTime = getTimeToday(nowTime, _sTime); firstTime.setTimeInMillis(getNext(firstTime.getTimeInMillis(), nowTime.getTimeInMillis(), _lPeriod)); Timer timer = new Timer(); timer.scheduleAtFixedRate(_task, firstTime.getTime(), _lPeriod); return timer; }
From source file:Main.java
public static void performDelayedInUiThread(final Activity activity, final Runnable task, int delay) { new Timer().schedule(new TimerTask() { @Override//from w w w. j a v a 2s. c o m public void run() { activity.runOnUiThread(task); } }, delay); }
From source file:com.sourcethought.simpledaemon.SimpleDaemon.java
@Override public void start() throws Exception { System.out.println("starting ..."); running = true;//from ww w . j a v a 2 s . co m timer = new Timer(); timer.schedule(new EchoTask(), 0, 1000); }
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);/* w ww . j ava 2 s . c om*/ 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.ifpe.poker.model.NewEmptyJUnitTest.java
@Test public void hello() { Timer timer = new Timer(); timer.schedule(new TimerTask() { int i = 10; @Override//w ww.j ava 2s. c o m public void run() { if (i <= 0) { cancel(); } System.out.println(i--); } }, 5000, 1000); // assertSame(player, list.get(0)); }
From source file:org.LexGrid.LexBIG.caCore.applicationservice.resource.TimedMap.java
@Override public void afterPropertiesSet() throws Exception { this.evictionTimer = new Timer(); this.evictionTimer.schedule(new TimerTask() { @Override/*from www . ja v a2s . c om*/ public void run() { long currentTime = System.currentTimeMillis(); for (K key : keySet()) { long originateTime = timeMap.get(key); if ((currentTime - timeToLive) >= originateTime) { remove(key); } } } }, checkPeriod, checkPeriod); }
From source file:Animation.java
public Animation() { display = Display.getDisplay(this); canvas = new AnimationCanvas(this); // Create task that fires off every 1/10 second tm = new Timer(); tt = new AnimateTimerTask(canvas); tm.schedule(tt, 0, 100);//www . j a va 2 s . co m }