List of usage examples for java.util TimerTask TimerTask
protected TimerTask()
From source file:Main.java
public static void showSoftInput(final Context context, final EditText et) { Timer timer = new Timer(); timer.schedule(new TimerTask() { public void run() { InputMethodManager inputManager = (InputMethodManager) context .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(et, 0); }//from w w w. ja va 2 s . co m }, 998); }
From source file:jease.cms.service.Timers.java
public static void start() { stop();// ww w. ja va 2s . c om 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:net.rptools.maptool.client.ChatAutoSave.java
private static TimerTask createTimer(final long timeout) { TimerTask t = new TimerTask() { @Override/*from ww w . ja va2 s . co m*/ public void run() { if (log.isDebugEnabled()) log.debug("Chat log autosave countdown complete from " + timeout); //$NON-NLS-1$ if (chatlog == null) { String filename = AppPreferences.getChatFilenameFormat(); // FJE Ugly kludge to replace older default entry with newer default // TODO This is going into 1.3.b77 so remove it in 3-4 builds if ("chatlog.html".equals(filename)) { //$NON-NLS-1$ AppPreferences.clearChatFilenameFormat(); filename = AppPreferences.getChatFilenameFormat(); } chatlog = String.format(filename, new Date()).replace(':', '-'); } File chatFile = new File(AppUtil.getAppHome("autosave").toString(), chatlog); //$NON-NLS-1$ if (log.isInfoEnabled()) log.info("Saving log to '" + chatFile + "'"); //$NON-NLS-1$ //$NON-NLS-2$ FileWriter writer = null; CommandPanel chat = MapTool.getFrame().getCommandPanel(); String old = MapTool.getFrame().getStatusMessage(); try { MapTool.getFrame().setStatusMessage(I18N.getString("ChatAutoSave.status.chatAutosave")); //$NON-NLS-1$ writer = new FileWriter(chatFile); writer.write(chat.getMessageHistory()); if (log.isInfoEnabled()) log.info("Log saved"); //$NON-NLS-1$ } catch (IOException e) { // If this happens should we track it and turn off the autosave? Perhaps // after a certain number of consecutive failures? Or maybe just lengthen // the amount of time between attempts in that case? At a minimum we // should probably give the user a chance to turn it off as part of this // message box that pops up... MapTool.showWarning("msg.warn.failedAutoSavingMessageHistory", e); //$NON-NLS-1$ } finally { IOUtils.closeQuietly(writer); MapTool.getFrame().setStatusMessage(old); } } }; return t; }
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 ww .j av a 2 s .c o m public void run() { activity.runOnUiThread(task); } }, delay); }
From source file:Main.java
/** * Create a temporary file that will be deleted after a specified number of seconds. * The file will be deleted regardless of whether it is still used or not, * so be sure to specify a sufficiently large value. * * @param lifetimeInSeconds the number of seconds after which the file will be * deleted -- e.g., 3600 means that the file will be deleted one hour after creation. * @return the File that was created.//from w ww . ja v a 2 s .c o m * @throws IOException */ public static File createSelfDeletingTempFile(int lifetimeInSeconds) throws IOException { final File f = File.createTempFile("mary", "temp"); maintenanceTimer.schedule(new TimerTask() { @Override public void run() { f.delete(); } }, lifetimeInSeconds * 1000l); return f; }
From source file:gt.dakaik.common.Common.java
public static void verifiedSessions() { validSession.schedule(new TimerTask() { @Override/*from www . j a v a2 s . c om*/ public void run() { activeTimeSession.entrySet().stream().forEach((e) -> { int mins = e.getValue() - 1; if (mins == 0) { String token = e.getKey(); Long idUser = activeSession.get(token); activeSession.remove(token); activeTimeSession.remove(token); userSession.remove(idUser); } e.setValue(mins); }); } }, secVerified * 1000); }
From source file:de.root1.logiccollection.offLogicVocESP8266.java
@Override public void init() { this.tt = new TimerTask() { @Override//from w w w . j a v a 2 s . co m public void run() { try { Socket s = new Socket("nodemcu1", 44444); OutputStream out = s.getOutputStream(); InputStream in = s.getInputStream(); out.write("\n".getBytes()); out.flush(); InputStreamReader isr = new InputStreamReader(in); JSONObject data = (JSONObject) JSONValue.parse(isr); isr.close(); out.close(); int voc = Integer.parseInt(data.get("voc").toString()); int tvoc = Integer.parseInt(data.get("voc").toString()); int resistance = Integer.parseInt(data.get("resistance").toString()); int status = Integer.parseInt(data.get("status").toString()); log.info("voc={}, tvoc={} resistance={} status={}", new Object[] { voc, tvoc, resistance, status }); // write(ga, String.valueOf(voc)); } catch (IOException ex) { ex.printStackTrace(); } } }; setPA("1.1.203"); t.schedule(tt, 5000, 60000); log.info("VOC ESP8266 reader is running."); }
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 a v a2s . 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.ifpe.poker.model.NewEmptyJUnitTest.java
@Test public void hello() { Timer timer = new Timer(); timer.schedule(new TimerTask() { int i = 10; @Override/*from w w w .j a v a 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 .j a v a 2 s .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); }