List of usage examples for java.util Timer Timer
public Timer()
From source file:monitoring.tools.ITunesApple.java
private void resetStream() throws Exception { kafka.initProxy(this.params.getKafkaEndpoint()); //kafka.initProducer(this.params.getKafkaEndpoint()); this.reported = new ArrayList<>(); firstConnection = true;// w ww .j a v a2s.co m firstApiCall(); timer = new Timer(); timer.schedule(new TimerTask() { public void run() { if (firstConnection) { logger.debug("Connection established"); firstConnection = false; System.out.println("First connection stablished"); } else { try { apiCall(); } catch (IOException e) { logger.error("There was an unexpected error with the API call"); } } } }, 0, Integer.parseInt(params.getTimeSlot()) * 1000); }
From source file:com.app.sniffy.MainActivity.java
@Override public void onStart() { super.onStart(); SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); if (settings.getString("key", null) != null) { if (!isMyServiceRunning()) { // intent to start service Intent mServiceIntent = new Intent(this, SentBoxService.class); startService(mServiceIntent); }//from ww w . j a v a 2s . c o m } if (storedKey != null) { timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { runOnUiThread(new Runnable() { public void run() { String currentTime = df.format(new Date()); String[] time = currentTime.split(","); TextView digi_time = (TextView) findViewById(R.id.digi_time); digi_time.setText(time[0]); TextView digi_time_meredian = (TextView) findViewById(R.id.digi_time_meredian); digi_time_meredian.setText(time[1]); TextView digi_time_day = (TextView) findViewById(R.id.digi_time_day); digi_time_day.setText(time[2] + ","); TextView digi_time_date = (TextView) findViewById(R.id.digi_time_date); digi_time_date.setText(time[3]); } }); } }, 0, 1000); } }
From source file:com.zh.snmp.snmpcore.snmp.trap.TimerUpdater.java
public void start() { if (running) { destroy();/*w ww . j a v a 2s .co m*/ } timer = new Timer(); long ms = periodInMinutes * 60 * 1000; timer.scheduleAtFixedRate(new DeviceUpdater(), ms, ms); msgAppender.addMessage("TimerUpdater.start", periodInMinutes); running = true; }
From source file:TimerMIDlet.java
/** * Changes the state of timers to/from active to/from * not-active./*from w w w .j av a 2 s. co m*/ */ private void flipFlop() { if (timersRunning) { timerTaskOne.cancel(); timerTaskTwo.cancel(); timer.cancel(); timersRunning = false; } else { timer = new Timer(); timerTaskOne = new MyTimerTask(gaugeOne, false); timerTaskTwo = new MyTimerTask(gaugeTwo, true); timer.schedule(timerTaskOne, 0, 1000); timer.schedule(timerTaskTwo, 0, 1500); timersRunning = true; } }
From source file:com.connectsdk.discovery.provider.CastDiscoveryProvider.java
@Override public void start() { stop();//from w w w . ja va2 s . c o m addCallbackTimer = new Timer(); addCallbackTimer.schedule(new TimerTask() { @Override public void run() { sendSearch(); } }, 100, RESCAN_INTERVAL); removeCallbackTimer = new Timer(); removeCallbackTimer.schedule(new TimerTask() { @Override public void run() { new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { mMediaRouter.removeCallback(mMediaRouterCallback); } }); } }, 9100, RESCAN_INTERVAL); }
From source file:com.gnizr.core.robot.rss.TestCrawlRssFeed.java
public void testRun() throws Exception { Timer timer = new Timer(); timer.schedule(crawlRssFeed, 0);/*from w w w .j a v a 2 s. c o m*/ crawlRssFeed.awaitAndShutdown(60, TimeUnit.SECONDS); Folder folder66 = folderManager.getUserFolder(new User(2), "latest news"); Folder folder67 = folderManager.getUserFolder(new User(2), "news2"); assertTrue(folder66.getSize() > 0); assertEquals(folder66.getSize(), folder67.getSize()); Folder importFolder = folderManager.getUserFolder(new User(2), FolderManager.IMPORTED_BOOKMARKS_LABEL); assertTrue(importFolder.getSize() > 0); Folder folder69 = folderManager.getUserFolder(new User(2), "georss data"); assertTrue(folder69.getSize() > 0); DaoResult<Bookmark> result2 = folderManager.pageFolderContent(new User(2), "georss data", 0, 1); Bookmark bm = result2.getResult().get(0); List<PointMarker> markers = bookmarkManager.getPointMarkers(bm); assertTrue(markers.size() > 0); }
From source file:fr.aliasource.webmail.proxy.impl.TimeOutMap.java
/** * @param timeout/*from w ww . ja v a2s . c om*/ * unused elements timeout in milliseconds */ public TimeOutMap(long timeout) { map = Collections.synchronizedMap(new HashMap<K, TimedItem<V>>()); this.timeout = timeout; executor = Executors.newFixedThreadPool(4); Timer t = new Timer(); t.scheduleAtFixedRate(new Remover(), 1000, timeout); }
From source file:Snooze.java
public void commandAction(Command c, Displayable s) { if (c == cmSnooze) { if (dateOK == false) { Alert al = new Alert("Unable to set alarm", "Please choose another date and time.", null, null); al.setTimeout(Alert.FOREVER); al.setType(AlertType.ERROR); display.setCurrent(al);/* ww w .j a v a2 s .co m*/ } else { // Create a new timer tmSnooze = new Timer(); ttSnooze = new SnoozeTimer(); // Amount of time to delay long amount = dfSnoozeTime.getDate().getTime() - currentTime.getTime(); tmSnooze.schedule(ttSnooze, amount); // Remove the commands fmMain.removeCommand(cmSnooze); fmMain.removeCommand(cmReset); // Remove the DateField fmMain.delete(dateIndex); // Change the Form message fmMain.setTitle("Snoozing..."); } } else if (c == cmReset) { // Reset to the current date/time dfSnoozeTime.setDate(currentTime = new Date()); } else if (c == cmExit) { destroyApp(false); notifyDestroyed(); } }
From source file:be.fgov.kszbcss.rhq.websphere.connector.notification.NotificationListenerManager.java
public NotificationListenerRegistration addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback, boolean extended) { NotificationListenerRegistration registration = new NotificationListenerRegistration(this, name, listener, filter, handback, extended); registration.update(adminClient);/*from w ww. j av a 2s . c om*/ synchronized (registrations) { registrations.add(registration); if (timer == null) { log.debug("Starting notification registration timer"); timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { updateRegistrations(); } }, 60000, 60000); } } return registration; }
From source file:morphy.user.SocketChannelUserSession.java
public SocketChannelUserSession(User user, SocketChannel channel) { this.user = user; this.channel = channel; inputBuffer = new StringBuilder(400); loginTime = System.currentTimeMillis(); objectMap = new TreeMap<UserSessionKey, Object>(); if (!UserService.getInstance().isAdmin(user.getUserName())) idleLogoutTimer = new Timer(); gamesObserving = new ArrayList<Integer>(); if (LOG.isInfoEnabled()) { LOG.info("Created SocketChannelUserSession user " + user.getUserName() + " " + channel.socket().getInetAddress()); }/*from w w w. j a v a2 s . com*/ multipleLogins = new ArrayList<SocketChannelUserSession>(0); }