List of usage examples for java.util.concurrent ScheduledExecutorService scheduleAtFixedRate
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit);
From source file:at.wada811.android.library.demos.concurrent.ExecutorActivity.java
/** * {@link ScheduledExecutorService#scheduleAtFixedRate(Runnable, long, long, TimeUnit)} * ??????// ww w .j a va 2 s . c om * * <p> * ????????????????????? * </p> */ public void newSingleThreadScheduledExecutorAtFixedRateTest() { LogUtils.d(); ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); executorService.scheduleAtFixedRate(new ExecutorRunnable("A", 1), 1, 2, TimeUnit.SECONDS); shutdown(executorService); }
From source file:at.wada811.android.library.demos.concurrent.ExecutorActivity.java
/** * {@link ScheduledExecutorService#scheduleAtFixedRate(Runnable, long, long, TimeUnit)} * ????/*w w w . jav a2s . c o m*/ * * <p> * ????????????????????? <br> * ?????????????????? * </p> */ public void newSingleThreadScheduledExecutorAtFixedRateDuringExecutionTest() { LogUtils.d(); ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); executorService.scheduleAtFixedRate(new ExecutorRunnable("A", 3), 1, 2, TimeUnit.SECONDS); shutdown(executorService); }
From source file:org.apache.stratos.common.concurrent.locks.ReadWriteLock.java
public ReadWriteLock(String name) { this.name = name; this.lock = new ReentrantReadWriteLock(true); this.threadToLockSetMap = new ConcurrentHashMap<Long, Map<LockType, LockMetadata>>(); readWriteLockMonitorEnabled = Boolean.getBoolean("read.write.lock.monitor.enabled"); if (readWriteLockMonitorEnabled) { // Schedule read write lock monitor readWriteLockMonitorInterval = Integer.getInteger("read.write.lock.monitor.interval", 30000); threadPoolSize = Integer.getInteger(READ_WRITE_LOCK_MONITOR_THREAD_POOL_SIZE_KEY, 10); ScheduledExecutorService scheduledExecutorService = StratosThreadPool .getScheduledExecutorService(READ_WRITE_LOCK_MONITOR_THREAD_POOL, threadPoolSize); scheduledExecutorService.scheduleAtFixedRate(new ReadWriteLockMonitor(this), readWriteLockMonitorInterval, readWriteLockMonitorInterval, TimeUnit.MILLISECONDS); if (log.isDebugEnabled()) { log.debug(String.format("Lock monitor scheduled: [lock-name] %s [interval] %d seconds", name, (readWriteLockMonitorInterval / 1000))); }//from w w w . j ava 2s . c om } }
From source file:be.vlaanderen.sesam.monitor.internal.util.ThreadPoolTaskScheduler.java
public ScheduledFuture scheduleAtFixedRate(Runnable task, Date startTime, long period) { ScheduledExecutorService executor = getScheduledExecutor(); long initialDelay = startTime.getTime() - System.currentTimeMillis(); try {/* w w w .j a va 2s.co m*/ return executor.scheduleAtFixedRate(errorHandlingTask(task, true), initialDelay, period, TimeUnit.MILLISECONDS); } catch (RejectedExecutionException ex) { throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex); } }
From source file:io.pravega.segmentstore.server.host.stat.AutoScaleProcessor.java
@VisibleForTesting AutoScaleProcessor(EventStreamWriter<AutoScaleEvent> writer, AutoScalerConfig configuration, Executor executor, ScheduledExecutorService maintenanceExecutor) { this(configuration, executor, maintenanceExecutor); this.writer.set(writer); this.initialized.set(true); maintenanceExecutor.scheduleAtFixedRate(cache::cleanUp, 0, configuration.getCacheCleanup().getSeconds(), TimeUnit.SECONDS);/*from ww w . j av a2 s . c o m*/ }
From source file:io.pravega.service.server.host.stat.AutoScaleProcessor.java
@VisibleForTesting AutoScaleProcessor(EventStreamWriter<ScaleEvent> writer, AutoScalerConfig configuration, Executor executor, ScheduledExecutorService maintenanceExecutor) { this(configuration, executor, maintenanceExecutor); this.writer.set(writer); this.initialized.set(true); maintenanceExecutor.scheduleAtFixedRate(cache::cleanUp, 0, configuration.getCacheCleanup().getSeconds(), TimeUnit.SECONDS);/*ww w . j a v a 2s. co m*/ }
From source file:org.tupelo_schneck.electric.ted.TedImporter.java
private ExecutorService repeatedlyImport(int count, boolean longImport, int interval) { ScheduledExecutorService execServ = Executors.newSingleThreadScheduledExecutor(); execServ.scheduleAtFixedRate(new MultiImporter(count, longImport), 0, interval, TimeUnit.SECONDS); return execServ; }
From source file:scouter.plugin.server.alert.telegram.TelegramPlugin.java
public TelegramPlugin() { if (ai.incrementAndGet() == 1) { ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); // thread count check executor.scheduleAtFixedRate(new Runnable() { @Override//from ww w. jav a 2s. com public void run() { for (int objHash : javaeeObjHashList) { try { if (AgentManager.isActive(objHash)) { ObjectPack objectPack = AgentManager.getAgent(objHash); MapPack mapPack = new MapPack(); mapPack.put("objHash", objHash); mapPack = AgentCall.call(objectPack, RequestCmd.OBJECT_THREAD_LIST, mapPack); int threadCountThreshold = conf.getInt("ext_plugin_thread_count_threshold", 0); int threadCount = mapPack.getList("name").size(); if (threadCountThreshold != 0 && threadCount > threadCountThreshold) { AlertPack ap = new AlertPack(); ap.level = AlertLevel.WARN; ap.objHash = objHash; ap.title = "Thread count exceed a threshold."; ap.message = objectPack.objName + "'s Thread count(" + threadCount + ") exceed a threshold."; ap.time = System.currentTimeMillis(); ap.objType = objectPack.objType; alert(ap); } } } catch (Exception e) { // ignore } } } }, 0, 5, TimeUnit.SECONDS); } }
From source file:org.wso2.carbon.identity.account.suspension.notification.task.handler.AccountSuspensionNotificationHandler.java
private void startScheduler() { if (!Boolean.parseBoolean( configs.getModuleProperties().getProperty(NotificationConstants.SUSPENSION_NOTIFICATION_ENABLED))) { return;// ww w . j a va 2 s. c o m } Date notificationTriggerTime = null; String notificationTriggerTimeProperty = configs.getModuleProperties() .getProperty(NotificationConstants.SUSPENSION_NOTIFICATION_TRIGGER_TIME); DateFormat dateFormat = new SimpleDateFormat(NotificationConstants.TRIGGER_TIME_FORMAT); if (notificationTriggerTimeProperty != null) { try { notificationTriggerTime = dateFormat.parse(notificationTriggerTimeProperty); } catch (ParseException e) { log.error("Invalid Date format for Notification trigger time", e); } } long schedulerDelayInSeconds = TimeUnit.HOURS.toSeconds(NotificationConstants.SCHEDULER_DELAY); Calendar currentTime = Calendar.getInstance(); Calendar triggerTime = Calendar.getInstance(); // If notificationTriggerTimeProperty is not found or not in right format default to 20:00:00. // In Calender.HOUR_OF_DAY (i.e. in 24-hour clock) it is 20. if (notificationTriggerTime != null) { triggerTime.setTime(notificationTriggerTime); } else { triggerTime.set(Calendar.HOUR_OF_DAY, 20); triggerTime.set(Calendar.MINUTE, 0); triggerTime.set(Calendar.SECOND, 0); } // Convert times into seconds long currentSecond = (currentTime.get(Calendar.HOUR_OF_DAY) * 3600) + currentTime.get(Calendar.MINUTE) * 60 + currentTime.get(Calendar.SECOND); long triggerSecond = (triggerTime.get(Calendar.HOUR_OF_DAY) * 3600) + triggerTime.get(Calendar.MINUTE) * 60 + triggerTime.get(Calendar.SECOND); long delay = triggerSecond - currentSecond; // If the notification time has passed, schedule the next day if (delay < 0) { delay += schedulerDelayInSeconds; } ScheduledExecutorService scheduler = Executors.newScheduledThreadPool( NotificationTaskDataHolder.getInstance().getNotificationSendingThreadPoolSize()); scheduler.scheduleAtFixedRate(new AccountValidatorThread(), delay, schedulerDelayInSeconds, TimeUnit.SECONDS); }
From source file:muvis.Environment.java
private Environment() { //Loading the main configuration ConfigurationFactory factory = new ConfigurationFactory("config.xml"); try {// w ww . j a v a2 s . co m configuration = factory.getConfiguration(); } catch (ConfigurationException ex) { System.out.println("Couldn't not load the configuration file! Possible reason: " + ex.toString()); } initializeDataFolders(); //initialize all the elements in the workspace audioPlayer = new MuVisAudioPlayer(); snippetManager = new AudioSnippetPlayerManager(audioPlayer); userPlaylist = new BasePlaylist(); configFile = new Properties(); viewManager = new ViewManager(); desk = new DockingDesktop(); ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); scheduler.scheduleAtFixedRate(new MemoryCollector(), 300, 300, TimeUnit.SECONDS); nbtreesManager = new NBTreeManager(); try { String dataFolder = configuration.getString("muvis.data_folder"); String nbtreeMainFolder = configuration.getString("muvis.nbtree_folder"); String nbtreeFullfolder = dataFolder + Util.getOSEscapeSequence() + nbtreeMainFolder + Util.getOSEscapeSequence(); nbtreesManager.addNBTree(Elements.TRACKS_NBTREE, new NBTree(Elements.TRACKS_NBTREE, nbtreeFullfolder)); nbtreesManager.addNBTree(Elements.ALBUMS_NBTREE, new NBTree(Elements.ALBUMS_NBTREE, nbtreeFullfolder)); nbtreesManager.addNBTree(Elements.ARTISTS_NBTREE, new NBTree(Elements.ARTISTS_NBTREE, nbtreeFullfolder)); } catch (NBTreeException ex) { ex.printStackTrace(); System.out.println("An error occured when trying to initialize the nbtreemanager!"); } initConfigFile(); }