List of usage examples for java.util Timer schedule
public void schedule(TimerTask task, Date firstTime, long period)
From source file:esg.node.components.notification.ESGNotifier.java
private void performNextNotification() { log.trace("launching notification timer"); long delay = Long.parseLong(props.getProperty("mail.notification.initialDelay")); long period = Long.parseLong(props.getProperty("mail.notification.period")); log.trace("notification delay: " + delay + " sec"); log.trace("notification period: " + period + " sec"); Timer timer = new Timer(); timer.schedule(new TimerTask() { public final void run() { //log.trace("Checking for new notification updates... [busy? "+ESGNotifier.this.isBusy+"]"); if (!ESGNotifier.this.isBusy) { ESGNotifier.this.isBusy = true; if (fetchNextUpdates()) { markTime();// w w w. j a va2 s . c o m } ESGNotifier.this.isBusy = false; } } }, delay * 1000, period * 1000); }
From source file:org.pepstock.jem.node.affinity.PolicyAffinityLoader.java
/** * Reads <code>jem.affinity.loader.policy</code> properties, passed by * configuration file/*w ww. j a va 2s. co m*/ * * @see org.pepstock.jem.node.affinity.AffinityLoader#init(java.util.Properties) */ @Override public final void init(Properties properties) { String fileName = properties.getProperty(POLICY_FILENAME_KEY); if (fileName != null) { scriptFile = new File(fileName); if (scriptFile.exists()) { Main.JOB_LIFECYCLE_LISTENERS_SYSTEM.addListener(JobLifecycleListener.class, this); FileAlterationObserver observer = new FileAlterationObserver(scriptFile.getParent()); FileAlterationMonitor monitor = new FileAlterationMonitor(POLLING_INTERVAL); observer.addListener(this); monitor.addObserver(observer); try { monitor.start(); } catch (Exception e) { // debug LogAppl.getInstance().debug(e.getMessage(), e); } String className = FilenameUtils.getExtension(this.getClass().getName()); Timer timer = new Timer(className, false); timer.schedule(new PeriodicallyAffinitiesReloader(), 5 * TimeUtils.MINUTE, 5 * TimeUtils.MINUTE); } } }
From source file:org.sipfoundry.sipxconfig.admin.BackupPlanTest.java
private void checkTimer(ScheduledDay day, long timerPeriod) { BackupPlan plan = new LocalBackupPlan(); DailyBackupSchedule schedule = new DailyBackupSchedule(); schedule.setEnabled(true);//from w w w . ja va 2 s. c o m schedule.setScheduledDay(day); plan.addSchedule(schedule); TimerTask task = plan.getTask("bin"); IMocksControl timerControl = EasyMock.createStrictControl(); Timer timer = timerControl.createMock(Timer.class); Date d = schedule.getTimerDate(); assertTrue(d.getTime() > System.currentTimeMillis()); // must be scheduled in the future timer.schedule(task, d, timerPeriod); timerControl.replay(); plan.schedule(timer, task); timerControl.verify(); }
From source file:uk.ac.imperial.presage2.core.cli.run.ExecutorManager.java
@Override public void run() { int poolSize = 0; for (SimulationExecutor exe : executors) { poolSize += exe.maxConcurrent(); }// ww w . j a v a 2s . com int queueSize = queue.size(); if (queue.contains(0L)) { queueSize--; } logger.info("Starting with " + queueSize + " simulations in the queue and " + executors.size() + " executors. Pool size is " + poolSize); startTime = System.currentTimeMillis(); // Checks every second and notifies if there are executors available. Timer executorChecker = new Timer(true); executorChecker.schedule(new TimerTask() { @Override public void run() { synchronized (ExecutorManager.this) { if (getNextExecutor() != null) ExecutorManager.this.notifyAll(); } } }, 1000, 1000); while (true) { try { // take head of queue / wait for a queue head long simId = queue.take(); // simId of 0 means end of queue, break from thread if we see it // and the queue is empty. Otherwise push it to the end of the // queue and continue. if (simId == 0) { if (queue.size() == 0) break; else { if (queue.peek() != 0) queue.offer(0L); continue; } } // get next executor / wait for executor synchronized (this) { SimulationExecutor exe; while ((exe = getNextExecutor()) == null) { logger.info("No Executors available, waiting."); logStatus(); wait(); } try { logger.info("Submitting simulation " + simId + " to executor: " + exe.toString()); exe.run(simId); submittedCount++; } catch (InsufficientResourcesException e) { queue.offer(simId); } } } catch (InterruptedException e1) { } } logger.debug("No more simulations to submit, waiting for executors to finish."); // wait for executors to finish for (SimulationExecutor exe : executors) { synchronized (this) { while (exe.running() > 0) { try { logger.debug("Waiting for executor to finish: " + exe.toString()); wait(); } catch (InterruptedException e) { } } } } logStatus(); logger.info("ExecutorManager shutting down."); }
From source file:com.spend.spendService.SearchText.java
private void Search() { try {// ww w . ja v a 2 s .c om 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:idgs.client.TcpClientPool.java
private void loadClientConfig() { log.debug(cfg.toString());/*from www. ja v a 2 s .co m*/ init(); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { int poolSize = -1; if (running.get() && (poolSize = size()) <= 0) { log.warn( "no available client to use, will auto create 2 multiples clients of config pool size"); newConnection(cfg.getPoolSize() * loadFactor); poolSize = size(); log.info("new pool size: " + poolSize); } } }, 5000, 3000); }
From source file:dk.netarkivet.wayback.aggregator.AggregationWorker.java
/** * Starts the aggregation task. Only allowed to be called once to avoid aggregation race conditions. *//*from w ww .j a v a2 s .co m*/ private void startAggregationThread() { if (aggregatorTask == null) { aggregatorTask = new TimerTask() { @Override public void run() { runAggregation(); } }; Timer aggregatorThreadTimer = new Timer("AggregatorThread"); aggregatorThreadTimer.schedule(aggregatorTask, 0, Settings.getLong(WaybackSettings.WAYBACK_AGGREGATOR_AGGREGATION_INTERVAL)); } else { throw new IllegalStateException("An attempt has been made to start a second aggregation job"); } }
From source file:org.apache.eagle.alert.engine.sorter.StreamSortHandlerTest.java
public void testWithTimerLock() throws InterruptedException { Timer timer = new Timer(); List<Long> collected = new ArrayList<>(); timer.schedule(new TimerTask() { @Override/* www . j a v a2s . c o m*/ public void run() { synchronized (collected) { LOG.info("Ticking {}", DateTimeUtil.millisecondsToHumanDateWithMilliseconds(System.currentTimeMillis())); collected.add(System.currentTimeMillis()); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } } } }, 0, 100); }
From source file:de.xirp.io.comm.lowlevel.AbstractStreamCommunicationInterface.java
/** * Sends data periodically.//from w w w .j av a 2 s.c o m * * @param name * the name to use for the send timer * @param time * the time interval in milliseconds between two sends * @param data * the data to send * @throws InvalidNameException * if the name is already in use */ public void sendPeriodically(String name, int time, byte[] data) throws InvalidNameException { if (periodicSenders.get(name) != null) { throw new InvalidNameException( I18n.getString("AbstractCommunication.log.alreadyExcecutingThread") + name); //$NON-NLS-1$ } Timer timer = new Timer(name); timer.schedule(getSendPeriodicTask(data), 0, time); periodicSenders.put(name, timer); }
From source file:com.example.hasan.sunshine.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The ArrayAdapter will take data from a source and // use it to populate the ListView it's attached to. mForecastAdapter = new ArrayAdapter<String>(getActivity(), // The current context (this activity) R.layout.list_item_forecast, // The name of the layout ID. R.id.list_item_forecast_textview, // The ID of the textview to populate. new ArrayList<String>()); View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); listView.setAdapter(mForecastAdapter); /*listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { //from w w w. j a va2 s . c om @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { String forecast = mForecastAdapter.getItem(position); Intent intent = new Intent(getActivity(), DetailActivity.class) .putExtra(Intent.EXTRA_TEXT, forecast); startActivity(intent); } });*/ WeatherTimerTask myTask = new WeatherTimerTask(); Timer myTimer = new Timer(); myTimer.schedule(myTask, 10000, 300000); return rootView; }