List of usage examples for java.util TimerTask TimerTask
protected TimerTask()
From source file:com.spend.spendService.SearchText.java
private void Search() { try {//from w w w . j a v a 2s . c o m TimerTask timertask = new TimerTask() { public void run() { try { String[] seList = getSearchEngineNamesArray(); /* get search queries from keywords table */ PreparedStatement psmt = con.prepareStatement("SELECT searchKeyword FROM keywords"); ResultSet rs = psmt.executeQuery(); while (rs.next()) { searchQuery = rs.getString("searchKeyword"); /* insert search queries into searchqueue table */ for (Object se : seList) { PreparedStatement psmt1 = con.prepareStatement( "INSERT INTO searchqueue(searchText,disabled,searchEngineName) VALUES(?,0,?);"); psmt1.setString(1, searchQuery); psmt1.setString(2, se.toString()); psmt1.executeUpdate(); psmt1.close(); } } } catch (Exception ex) { System.out.println("SearchText.java timertask run function SQL ERROR " + ex.getMessage()); } } }; Timer timer = new Timer(); DateFormat dateformat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); Date date = dateformat.parse("20-07-2017 00:00:00"); // set time and date timer.schedule(timertask, date, 1000 * 60 * 60 * 24); // for 24 hour 1000*60*60*24 } catch (Exception ex) { System.out.println("SearchText.java Search function ERROR " + ex.getMessage()); } }
From source file:airport.dispatcher.weather.HydrometeorologicalServiceImpl.java
public void startTimerTask(long period) { timerTaskUpdateWeather = new TimerTask() { @Override/*from www . j a va2 s. c om*/ public void run() { if (LOG.isInfoEnabled()) { LOG.info("weather update"); } weather.update(); } }; timerUpdateWeather.schedule(timerTaskUpdateWeather, DELAY, period); }
From source file:com.pureinfo.force.util.TimerUtilTest.java
public void testScheduleFrom() throws InterruptedException { TimerUtil.scheduleFrom("11:20", DateUtils.MILLIS_PER_SECOND, new TimerTask() { private int i = 0; public void run() { System.out.println(i++); // if (i == 5) timer.cancel(); }// w w w.j av a2 s. c om }); Thread.sleep(10000); }
From source file:com.spend.spendService.DomainLearning.java
private void GetNewQuery() { try {/*from w ww . j a v a 2 s.c o m*/ TimerTask timertask = new TimerTask() { public void run() { try { domainList = new ArrayList<String>(); String[] seList = getSearchEngineNamesArray(); /* get urls from seedurlraw table */ PreparedStatement psmt = con.prepareStatement("SELECT url FROM seedurlraw"); ResultSet rs = psmt.executeQuery(); String regex = "[/]"; String regex2 = "[.]"; String PLDomain; while (rs.next()) { PLDomain = rs.getString("url"); PLDomain = PLDomain.replaceAll("http://|https://", ""); Pattern p = Pattern.compile(regex); Matcher m = p.matcher(PLDomain); if (m.find()) { PLDomain = PLDomain.substring(0, m.start()); } Pattern p2 = Pattern.compile(regex2); Matcher m2 = p2.matcher(PLDomain); int count = 0; while (m2.find()) { count++; } m2 = p2.matcher(PLDomain); if (count > 1 && m2.find()) { PLDomain = PLDomain.substring(m2.end()); } //System.out.println(PLDomain); if (!domainList.contains(PLDomain)) { domainList.add(PLDomain); newQuery = "sparql endpoint site:" + PLDomain; for (Object se : seList) { PreparedStatement psmt1 = con.prepareStatement( "INSERT INTO searchqueue(searchText,disabled,searchEngineName) VALUES(?,0,?);"); psmt1.setString(1, newQuery); psmt1.setString(2, se.toString()); psmt1.executeUpdate(); psmt1.close(); } } } } catch (Exception ex) { System.out .println("DomainLearning.java timertask run function SQL ERROR " + ex.getMessage()); } } }; Timer timer = new Timer(); DateFormat dateformat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); Date date = dateformat.parse("20-07-2017 00:00:00"); // set date and time timer.schedule(timertask, date, 1000 * 60 * 60 * 24 * 7); // for a week 1000*60*60*24*7 } catch (Exception ex) { System.out.println("DomainLearning.java GetNewQuery function ERROR " + ex.getMessage()); } }
From source file:com.pureinfo.srm.sender.engines.SRMMailEngine.java
protected void doStartup() throws PureException { if (logger.isInfoEnabled()) { logger.info("mail engine startup."); }// w w w .j a v a2 s .com m_timer = new Timer(); m_timer.schedule(new TimerTask() { public void run() { try { SRMMailMachine machine = new SRMMailMachine(); machine.send(); } catch (Exception e) { logger.warn("mail engine error,", e); } } }, DELAY, PERIOD); }
From source file:drusy.ui.panels.SwitchStatePanel.java
public void updatePeriodically() { long delay = 1000 * 2; timer = new java.util.Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override//from w w w . j av a 2 s. com public void run() { update(fakeUpdater); } }, 1000, delay); }
From source file:drusy.ui.panels.WifiStatePanel.java
public void updatePeriodically() { long delay = 1000 * 2; timer = new java.util.Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override//from w ww. j ava 2 s . c o m public void run() { update(fakeUpdater); } }, 500, delay); }
From source file:com.offbynull.portmapper.common.ProcessUtils.java
/** * Run a process and dump the stdout stream to a string. * @param timeout maximum amount of time the process can take to run * @param command command//w w w .java2 s . co m * @param args arguments * @return stdout from the process dumped to a string * @throws IOException if the process encounters an error * @throws NullPointerException if any arguments are {@code null} or contains {@code null} * @throws IllegalArgumentException any numeric argument is negative */ public static String runProcessAndDumpOutput(long timeout, String command, String... args) throws IOException { Validate.notNull(command); Validate.noNullElements(args); Validate.inclusiveBetween(0L, Long.MAX_VALUE, timeout); String[] pbCmd = new String[args.length + 1]; pbCmd[0] = command; System.arraycopy(args, 0, pbCmd, 1, args.length); ProcessBuilder builder = new ProcessBuilder(pbCmd); final AtomicBoolean failedFlag = new AtomicBoolean(); Timer timer = new Timer("Process timeout timer", true); Process proc = null; try { proc = builder.start(); final Process finalProc = proc; timer.schedule(new TimerTask() { @Override public void run() { failedFlag.set(true); finalProc.destroy(); } }, timeout); String ret = IOUtils.toString(proc.getInputStream()); if (failedFlag.get()) { throw new IOException("Process failed"); } return ret; } finally { if (proc != null) { proc.destroy(); } timer.cancel(); timer.purge(); } }
From source file:com.pureinfo.srm.sendoutlayunit.engines.SRMOutlayUnitEngine.java
protected void doStartup() throws PureException { // TODO Auto-generated method stub if (logger.isInfoEnabled()) { logger.info("outlayunit engine startup."); }//from w w w . jav a 2 s. c om m_timer = new Timer(); m_timer.schedule(new TimerTask() { public void run() { try { } catch (Exception e) { logger.warn("outlayunit engine error,", e); } } }, DELAY, PERIOD); }