List of usage examples for java.util.concurrent Executors newSingleThreadScheduledExecutor
public static ScheduledExecutorService newSingleThreadScheduledExecutor()
From source file:org.rioproject.examples.hospital.ui.PatientStatsPanel.java
public PatientStatsPanel() { super(new BorderLayout(8, 8)); setBorder(BorderFactory.createEmptyBorder(2, 8, 8, 8)); patientLabel = new JLabel(getLabelText(null)); add(patientLabel, BorderLayout.NORTH); pulseTimeSeries.setMaximumItemAge(5 * MINUTE); temperatureTimeSeries.setMaximumItemAge(5 * MINUTE); TimeSeriesCollection pulseDataSet = new TimeSeriesCollection(pulseTimeSeries); TimeSeriesCollection temperatureDataSet = new TimeSeriesCollection(temperatureTimeSeries); JFreeChart pulseChart = createTimeSeriesChart(pulseDataSet, Color.RED); JFreeChart temperatureChart = createTimeSeriesChart(temperatureDataSet, Color.BLUE); JPanel chartPanel = new JPanel(new GridLayout(1, 2)); chartPanel.add(makeChartPanel(pulseChart)); chartPanel.add(makeChartPanel(temperatureChart)); add(chartPanel, BorderLayout.CENTER); scheduler = Executors.newSingleThreadScheduledExecutor(); scheduler.scheduleAtFixedRate(new FeederTask(), 0, 2, TimeUnit.SECONDS); }
From source file:nl.esciencecenter.osmium.job.XenonManager.java
/** * Sets preferences in GAT context and initializes a broker. * * @param configuration Configuration for Xenon * @throws XenonException if Xenon could not be configured *//*from w w w .j a va 2s . c o m*/ public XenonManager(XenonConfiguration configuration) throws XenonException { this.configuration = configuration; xenon = XenonFactory.newXenon(configuration.getPreferences()); scheduler = newScheduler(); sandboxRootPath = newSandboxRootPath(); jobs = new ConcurrentHashMap<String, SandboxedJob>(); executor = Executors.newSingleThreadScheduledExecutor(); PollConfiguration pollConf = configuration.getPoll(); poller = new JobsPoller(jobs, pollConf, xenon); }
From source file:org.wso2.carbon.registry.indexing.IndexingManager.java
public synchronized void startIndexing() { stopIndexing(); //stop executors if they are already running, otherwise they will never stop if (registryConfig.IsStartIndexing()) { submittingExecutor = Executors.newSingleThreadScheduledExecutor(); submittingExecutor.scheduleWithFixedDelay(new ResourceSubmitter(this), getStartingDelayInSecs(), getIndexingFreqInSecs(), TimeUnit.SECONDS); indexingExecutor = Executors.newSingleThreadScheduledExecutor(); indexingExecutor.scheduleWithFixedDelay(indexer, getStartingDelayInSecs(), getIndexingFreqInSecs(), TimeUnit.SECONDS); readLastAccessTime();//from w w w . j a va 2 s . c o m } }
From source file:org.whispersystems.gcm.server.Sender.java
@VisibleForTesting public Sender(String apiKey, int retryCount, String url) { ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); this.url = url; this.authorizationHeader = String.format("key=%s", apiKey); this.client = HttpAsyncClients.custom().setMaxConnTotal(100).setMaxConnPerRoute(10).build(); this.executor = new AsyncRetryExecutor(scheduler).retryOn(ServerFailedException.class) .retryOn(TimeoutException.class).retryOn(IOException.class).withExponentialBackoff(100, 2.0) .withUniformJitter().withMaxDelay(4000).withMaxRetries(retryCount); this.client.start(); }
From source file:org.zalando.spring.boot.scheduling.CustomSchedulingConfiguration.java
@Override public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { if (properties.isEnabled()) { if (taskScheduler != null) { taskRegistrar.setScheduler(taskScheduler); } else {//from ww w . j a v a 2 s . co m throw new BeanCreationException("Expecting a 'ConcurrentTaskScheduler' injected, but was 'null'"); } } else { log.info("'CustomSchedulingConfiguration' is disabled, create a default - 'ConcurrentTaskScheduler'"); this.localExecutor = Executors.newSingleThreadScheduledExecutor(); taskRegistrar.setScheduler(new ConcurrentTaskScheduler(localExecutor)); } }
From source file:org.vaadin.spring.i18n.MessageProviderCacheCleanupExecutor.java
/** * Creates a new {@code MessageProviderCacheCleanupExecutor} and starts up the cleanup thread if cache cleanup * has been enabled./*from w ww.j a va 2s. c o m*/ */ public MessageProviderCacheCleanupExecutor(final Environment environment, final CompositeMessageSource compositeMessageSource) { cleanupInterval = environment.getProperty(ENV_PROP_MESSAGE_PROVIDER_CACHE_CLEANUP_INTERVAL_SECONDS, Integer.class, 0); if (cleanupInterval > 0) { if (compositeMessageSource.isMessageFormatCacheEnabled()) { LOGGER.warn( "The message format cache is enabled so message provider cache cleanup will not have any effect, disabling"); } else { LOGGER.info("Cleaning up the message provider caches every {} second(s)", cleanupInterval); executorService = Executors.newSingleThreadScheduledExecutor(); cleanupJob = executorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { LOGGER.debug("Cleaning up message provider caches"); compositeMessageSource.clearMessageProviderCaches(); } }, cleanupInterval, cleanupInterval, TimeUnit.SECONDS); } } else { LOGGER.info("Message provider cache cleanup is disabled"); } }
From source file:com.chiralBehaviors.slp.hive.hardtack.configuration.PushConfiguration.java
@Override public Engine construct() throws IOException { NetworkInterface intf = getNetworkInterface(); InetAddress address = Utils.getAddress(intf, ipv4); DatagramSocket p2pSocket = new DatagramSocket(new InetSocketAddress(address, Utils.allocatePort(address))); int i = 0;/*from w w w . j a v a 2 s. c om*/ for (InetSocketAddress aggregator : aggregators) { log.info(String.format("Adding aggregator: %s", aggregator)); if (aggregator.getAddress().isAnyLocalAddress()) { aggregators.set(i++, new InetSocketAddress(address, aggregator.getPort())); } } return new PushEngine(p2pSocket, getMac(), Generators.timeBasedGenerator(), aggregators, heartbeatPeriod, heartbeatUnit, Executors.newSingleThreadScheduledExecutor()); }
From source file:org.kairosdb.plugin.announce.AnnounceService.java
@Inject public AnnounceService(@Named("kairosdb.plugin.announce.discovery.hosts") String discoveryHosts, @Named("kairosdb.plugin.announce.discovery.port") int discoveryPort, @Named("kairosdb.plugin.announce.environment") String environment, @Named("kairosdb.plugin.announce.pool") String pool) { m_environment = environment;// w ww. ja va2s.c om m_pool = pool; m_discoveryUrls = new ArrayList<String>(); String[] hosts = discoveryHosts.split(","); for (String host : hosts) { host = host.trim(); m_discoveryUrls.add("http://" + host + ":" + discoveryPort); } m_executorService = Executors.newSingleThreadScheduledExecutor(); }
From source file:org.mule.transport.polling.schedule.FixedFrequencyScheduler.java
/** * <p>/* w w w. ja va 2s. c o m*/ * Starts the Scheduling of a Task. Can be called several times, if the {@link Scheduler} is already started or * if it is starting then the start request is omitted * </p> */ @Override public void start() throws MuleException { if (isNotStarted()) { lifecycleManager.fireStartPhase(new LifecycleCallback<Scheduler>() { @Override public void onTransition(String phaseName, Scheduler object) throws MuleException { executor.shutdown(); executor = Executors.newSingleThreadScheduledExecutor(); ((ScheduledExecutorService) executor).scheduleAtFixedRate(job, startDelay, frequency, timeUnit); } }); } }
From source file:sse.es.EventSourceServlet.java
@Override public void init() throws ServletException { String heartBeatPeriodParam = getServletConfig().getInitParameter("heartBeatPeriod"); if (heartBeatPeriodParam != null) heartBeatPeriod = Integer.parseInt(heartBeatPeriodParam); scheduler = Executors.newSingleThreadScheduledExecutor(); }