List of usage examples for java.util TimerTask TimerTask
protected TimerTask()
From source file:org.mitre.ptmatchadapter.PtmatchAdapter.java
public static void main(String... args) { // Create a one-time task that will open a url to config page in a browser // after the application has been given a couple of seconds to start up. new Timer().schedule(new TimerTask() { @Override//from w ww. ja v a 2 s . c om public void run() { LOG.info("============= Open URL in Browser"); // Open a Browser window for the user BareBonesBrowserLaunch.openURL("http://localhost:8082/index.html"); LOG.info("============= After Open URL in Browser"); } }, 9000); LOG.info("============= Call Fat Jar Router Main"); // Call Fat Jar Router main last because it never returns FatJarRouter.main(args); LOG.info("============= Returned from Fat Jar Router Main"); }
From source file:edu.hawaii.soest.kilonalu.utilities.FileArchiverSink.java
/** * Runs FileArchiverSink.//from w w w . j av a 2s.c o m * * @param args the command line arguments */ public static void main(String[] args) { // Set up a simple logger that logs to the console BasicConfigurator.configure(); final FileArchiverSink fileArchiverSink = new FileArchiverSink(); if (fileArchiverSink.parseArgs(args)) { setupShutdownHook(fileArchiverSink); setupProgressListener(fileArchiverSink); // archive data on a schedule if (fileArchiverSink.getArchiveInterval() > 0) { // override the command line start and end times fileArchiverSink.setupArchiveTime(fileArchiverSink); TimerTask archiveData = new TimerTask() { public void run() { logger.debug("TimerTask.run() called."); if (fileArchiverSink.validateSetup()) { fileArchiverSink.export(); fileArchiverSink.setupArchiveTime(fileArchiverSink); } } }; Timer archiveTimer = new Timer(); // run the archiveData timer task on the hour, every hour (or every day) archiveTimer.scheduleAtFixedRate(archiveData, endArchiveCal.getTime(), fileArchiverSink.getArchiveInterval() * 1000); // archive data once based on the start and end times } else { fileArchiverSink.export(); } } }
From source file:Main.java
public static void startThreadStatusTimer(final Thread t1) { new Timer().schedule(new TimerTask() { @Override//ww w .j a v a2s . c om public void run() { System.out.println("\t\t\t\t\t\t\t\t\t\tThread(" + t1.getName() + ") state - " + t1.getState()); } }, 0, 1000); }
From source file:Main.java
public static void doLater(long delay, final Runnable runnable) { Timer t = new Timer(); t.schedule(new TimerTask() { @Override/*www .j av a 2 s . c om*/ public void run() { SwingUtilities.invokeLater(runnable); } }, delay); }
From source file:Main.java
public static void delayToActivity(final Context context, final Class<?> cls, long delay) { Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override//from w ww. j ava 2 s .com public void run() { context.startActivity(new Intent(context, cls)); } }, delay); }
From source file:Main.java
public static Timer setTimeOut(final Runnable runnable, int delayMillis) { final Handler handler = new Handler(); final Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override// w ww . ja v a 2 s . c om public void run() { handler.post(runnable); timer.cancel(); } }, delayMillis); return timer; }
From source file:Main.java
public static Timer setInterval(final Runnable runnable, int delayMillis, int period) { final Handler handler = new Handler(); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override//from www.ja va 2 s . c o m public void run() { handler.post(runnable); } }, delayMillis, period); return timer; }
From source file:Main.java
public static void showInputMethodManager(final EditText editText) { Timer timer = new Timer(); timer.schedule(new TimerTask() { public void run() { InputMethodManager inputManager = (InputMethodManager) editText.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(editText, 0); }/* w w w .j a v a 2 s . c o m*/ }, 200); }
From source file:Main.java
public static void startThreadStatusTimer(final Thread t1, int ms) { new Timer().schedule(new TimerTask() { @Override// www. j a v a2s.com public void run() { System.out.println("\t\t\t\t\t\t\t\t\t\tThread(" + t1.getName() + ") state - " + t1.getState()); } }, 0, ms); }
From source file:JTop.java
public static void main(String[] args) throws Exception { // Validate the input arguments if (args.length != 1) { usage();/* w w w .ja v a 2 s .c o m*/ } String[] arg2 = args[0].split(":"); if (arg2.length != 2) { usage(); } String hostname = arg2[0]; int port = -1; try { port = Integer.parseInt(arg2[1]); } catch (NumberFormatException x) { usage(); } if (port < 0) { usage(); } // Create the JTop Panel final JTop jtop = new JTop(); // Set up the MBeanServerConnection to the target VM MBeanServerConnection server = connect(hostname, port); jtop.setMBeanServerConnection(server); // A timer task to update GUI per each interval TimerTask timerTask = new TimerTask() { public void run() { // Schedule the SwingWorker to update the GUI jtop.newSwingWorker().execute(); } }; // Create the standalone window with JTop panel // by the event dispatcher thread SwingUtilities.invokeAndWait(new Runnable() { public void run() { createAndShowGUI(jtop); } }); // refresh every 2 seconds Timer timer = new Timer("JTop Sampling thread"); timer.schedule(timerTask, 0, 2000); }