List of usage examples for java.util.concurrent Executors newSingleThreadScheduledExecutor
public static ScheduledExecutorService newSingleThreadScheduledExecutor(ThreadFactory threadFactory)
From source file:net.centro.rtb.monitoringcenter.metrics.tomcat.TomcatMetricSet.java
public TomcatMetricSet() { this.mBeanServer = ManagementFactory.getPlatformMBeanServer(); Map<String, Metric> metricsByNames = new HashMap<>(); // Executors// w ww . j a v a 2 s .c om List<TomcatExecutorStatus> executorStatuses = new ArrayList<>(); Set<ObjectName> executorObjectNames = null; try { executorObjectNames = mBeanServer.queryNames(new ObjectName("Catalina:type=Executor,*"), null); } catch (MalformedObjectNameException e) { logger.debug("Invalid ObjectName defined for the Tomcat's Executor MxBean", e); } if (executorObjectNames != null && !executorObjectNames.isEmpty()) { for (final ObjectName executorObjectName : executorObjectNames) { TomcatExecutorMetricSet executorMetricSet = new TomcatExecutorMetricSet(executorObjectName); if (!executorMetricSet.getMetrics().isEmpty()) { metricsByNames.put(MetricNamingUtil.join("executors", executorMetricSet.getName()), executorMetricSet); } executorStatuses.add(executorMetricSet); } } this.executorStatuses = executorStatuses; // Thread Pools final List<TomcatConnectorMetricSet> connectorMetricSets = new ArrayList<>(); List<TomcatConnectorStatus> connectorStatuses = new ArrayList<>(); Set<ObjectName> threadPoolObjectNames = null; try { threadPoolObjectNames = mBeanServer.queryNames(new ObjectName("Catalina:type=ThreadPool,*"), null); } catch (MalformedObjectNameException e) { logger.debug("Invalid ObjectName defined for the Tomcat's ThreadPool MxBean", e); } if (threadPoolObjectNames != null && !threadPoolObjectNames.isEmpty()) { for (final ObjectName threadPoolObjectName : threadPoolObjectNames) { TomcatConnectorMetricSet connectorMetricSet = new TomcatConnectorMetricSet(threadPoolObjectName); if (!connectorMetricSet.getMetrics().isEmpty()) { metricsByNames.put(MetricNamingUtil.join("connectors", connectorMetricSet.getName()), connectorMetricSet); connectorMetricSets.add(connectorMetricSet); } connectorStatuses.add(connectorMetricSet); } } this.connectorStatuses = connectorStatuses; if (!connectorMetricSets.isEmpty()) { this.executorService = Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder().setNameFormat("TomcatMetricSet-%d").build()); this.executorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { for (TomcatConnectorMetricSet connectorMetricSet : connectorMetricSets) { try { connectorMetricSet.updateQps(); } catch (Exception e) { logger.debug("Error while updating QPS for connector {}", connectorMetricSet.getName(), e); if (InterruptedException.class.isInstance(e)) { Thread.currentThread().interrupt(); } } } } }, 1, 1, TimeUnit.SECONDS); } this.metricsByNames = metricsByNames; this.shutdown = new AtomicBoolean(false); }
From source file:com.pinterest.pinlater.backends.mysql.PinLaterMySQLBackend.java
/** * Creates an instance of the PinLaterMySQLBackend. * * @param configuration configuration parameters for the backend. * @param serverHostName hostname of the PinLater server. * @param serverStartTimeMillis start time of the PinLater server. *///from w w w . jav a 2 s .c o m public PinLaterMySQLBackend(PropertiesConfiguration configuration, String serverHostName, long serverStartTimeMillis) throws Exception { super(configuration, "MySQL", serverHostName, serverStartTimeMillis); this.configuration = Preconditions.checkNotNull(configuration); this.countLimit = configuration.getInt("MYSQL_COUNT_LIMIT"); this.numDbPerQueue = configuration.getInt("MYSQL_NUM_DB_PER_QUEUE", 1); this.mySQLHealthMonitor = new MySQLHealthMonitor(new HashSet<String>()); // Start the JobQueueMonitor scheduled task. this.queueMonitorService = Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder().setDaemon(true).setNameFormat("MySQLJobQueueMonitor-%d").build()); // Call Base class's initialization function to initialize the shardMap, futurePool and dequeue // semaphoreMap. initialize(); }
From source file:net.rptools.tokentool.controller.ManageOverlays_Controller.java
@FXML void initialize() { assert overlayViewFlowPane != null : "fx:id=\"overlayViewFlowPane\" was not injected: check your FXML file 'ManageOverlays.fxml'."; assert overlayTreeView != null : "fx:id=\"overlayTreeView\" was not injected: check your FXML file 'ManageOverlays.fxml'."; assert detailsVBox != null : "fx:id=\"detailsVBox\" was not injected: check your FXML file 'ManageOverlays.fxml'."; assert overlayName != null : "fx:id=\"overlayName\" was not injected: check your FXML file 'ManageOverlays.fxml'."; assert overlayDescription != null : "fx:id=\"overlayDescription\" was not injected: check your FXML file 'ManageOverlays.fxml'."; assert overlayDimensions != null : "fx:id=\"overlayDimensions\" was not injected: check your FXML file 'ManageOverlays.fxml'."; assert overlayLayerImage != null : "fx:id=\"overlayLayerImage\" was not injected: check your FXML file 'ManageOverlays.fxml'."; assert overlayLayerMask != null : "fx:id=\"overlayLayerMask\" was not injected: check your FXML file 'ManageOverlays.fxml'."; assert addOverlayButton != null : "fx:id=\"addOverlayButton\" was not injected: check your FXML file 'ManageOverlays.fxml'."; assert deleteOverlayButton != null : "fx:id=\"deleteOverlayButton\" was not injected: check your FXML file 'ManageOverlays.fxml'."; assert addFolderButton != null : "fx:id=\"addFolderButton\" was not injected: check your FXML file 'ManageOverlays.fxml'."; assert deleteFolderButton != null : "fx:id=\"deleteFolderButton\" was not injected: check your FXML file 'ManageOverlays.fxml'."; assert restoreButton != null : "fx:id=\"restoreButton\" was not injected: check your FXML file 'ManageOverlays.fxml'."; executorService = Executors.newSingleThreadScheduledExecutor(runable -> { loadOverlaysThread = Executors.defaultThreadFactory().newThread(runable); loadOverlaysThread.setDaemon(true); return loadOverlaysThread; });//w ww. ja v a 2s . c o m // Add a listener to the TreeView overlayTreeView.getSelectionModel().selectedItemProperty() .addListener((observable, oldValue, newValue) -> loadImages(newValue)); displayTreeView(); }
From source file:com.clustercontrol.agent.custom.CommandResultForwarder.java
private CommandResultForwarder() { {// w w w . j a v a2 s .co m String key = "monitor.custom.forwarding.queue.maxsize"; int valueDefault = 5000; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _queueMaxSize = value; } { String key = "monitor.custom.forwarding.transport.maxsize"; int valueDefault = 100; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportMaxSize = value; } { String key = "monitor.custom.forwarding.transport.maxtries"; int valueDefault = 900; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportMaxTries = value; } { String key = "monitor.custom.forwarding.transport.interval.size"; int valueDefault = 15; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportIntervalSize = value; } { String key = "monitor.custom.forwarding.transport.interval.msec"; long valueDefault = 1000L; String str = AgentProperties.getProperty(key); long value = valueDefault; try { value = Long.parseLong(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportIntervalMSec = value; } _scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { private volatile int _count = 0; @Override public Thread newThread(Runnable r) { Thread t = new Thread(r, CommandResultForwarder.class.getSimpleName() + _count++); t.setDaemon(true); return t; } }); if (_transportIntervalMSec != -1) { _scheduler.scheduleWithFixedDelay(new ScheduledTask(), 0, _transportIntervalMSec, TimeUnit.MILLISECONDS); } }
From source file:org.wso2.andes.kernel.FlowControlManager.java
public FlowControlManager() { // Read configured limits globalLowLimit = (Integer) AndesConfigurationManager .readValue(AndesConfiguration.FLOW_CONTROL_GLOBAL_LOW_LIMIT); globalHighLimit = (Integer) AndesConfigurationManager .readValue(AndesConfiguration.FLOW_CONTROL_GLOBAL_HIGH_LIMIT); channelLowLimit = ((Integer) AndesConfigurationManager .readValue(AndesConfiguration.FLOW_CONTROL_BUFFER_BASED_LOW_LIMIT)); channelHighLimit = ((Integer) AndesConfigurationManager .readValue(AndesConfiguration.FLOW_CONTROL_BUFFER_BASED_HIGH_LIMIT)); if (globalHighLimit <= globalLowLimit || channelHighLimit <= channelLowLimit) { throw new RuntimeException("Flow Control limits are not configured correctly."); }/* w ww. j a v a 2 s . c om*/ messagesOnGlobalBuffer = new AtomicInteger(0); globalBufferBasedFlowControlEnabled = false; globalErrorBasedFlowControlEnabled = false; channels = new ArrayList<AndesChannel>(); FailureObservingStoreManager.registerStoreHealthListener(this); if (AndesContext.getInstance().isClusteringEnabled()) { // network partition detection works only when clustered. AndesContext.getInstance().getClusterAgent().addNetworkPartitionListener(20, this); } // Initialize executor service for state validity checking ThreadFactory namedThreadFactory = new ThreadFactoryBuilder() .setNameFormat("AndesScheduledTaskManager-FlowControl").build(); executor = Executors.newSingleThreadScheduledExecutor(namedThreadFactory); //Will start the gauge MetricManager.gauge(MetricsConstants.ACTIVE_CHANNELS, Level.INFO, new ChannelGauge()); }
From source file:rapture.dp.WorkflowMetricsTest.java
@Before public void before() throws NoSuchFieldException, IllegalAccessException { globalMetricNames = new HashSet<>(); Kernel.INSTANCE.restart();/*from ww w .j ava 2 s . c o m*/ Kernel.initBootstrap(); Field field = Kernel.class.getDeclaredField("metricsService"); field.setAccessible(true); metricsService = createMetricsService(globalMetricNames); field.set(Kernel.INSTANCE, metricsService); Kernel.getPipeline().setupStandardCategory(CTX, CATEGORY); Kernel.setCategoryMembership(CATEGORY); ThreadFactory tf = new ThreadFactoryBuilder().setNameFormat("WorkflowMetricsTest-ScheduleManager").build(); scheduler = Executors.newSingleThreadScheduledExecutor(tf); scheduler.scheduleWithFixedDelay(new Runnable() { @Override public void run() { try { ScheduleManager.manageJobExecStatus(); JOB_SEMAPHORE.release(); } catch (Exception e) { log.error(String.format("Got exception %s when running a task, the show goes on. stack: %s", e.getMessage(), ExceptionToString.format(e))); } } }, 0, 100, TimeUnit.MILLISECONDS); }
From source file:com.clustercontrol.agent.log.LogfileResultForwarder.java
private LogfileResultForwarder() { {//from w ww . ja va2 s. c om String key = "monitor.logfile.forwarding.queue.maxsize"; int valueDefault = 5000; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _queueMaxSize = value; } { String key = "monitor.logfile.forwarding.transport.maxsize"; int valueDefault = 100; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportMaxSize = value; } { String key = "monitor.logfile.forwarding.transport.maxtries"; int valueDefault = 900; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportMaxTries = value; } { String key = "monitor.logfile.forwarding.transport.interval.size"; int valueDefault = 15; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportIntervalSize = value; } { String key = "monitor.logfile.forwarding.transport.interval.msec"; long valueDefault = 1000L; String str = AgentProperties.getProperty(key); long value = valueDefault; try { value = Long.parseLong(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportIntervalMSec = value; } _scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { private volatile int _count = 0; @Override public Thread newThread(Runnable r) { Thread t = new Thread(r, LogfileResultForwarder.class.getSimpleName() + _count++); t.setDaemon(true); return t; } }); if (_transportIntervalMSec != -1) { _scheduler.scheduleWithFixedDelay(new ScheduledTask(), 0, _transportIntervalMSec, TimeUnit.MILLISECONDS); } }
From source file:com.clustercontrol.agent.winevent.WinEventResultForwarder.java
private WinEventResultForwarder() { {/*w w w. java 2 s .c o m*/ String key = "monitor.winevent.forwarding.queue.maxsize"; int valueDefault = 5000; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _queueMaxSize = value; } { String key = "monitor.winevent.forwarding.transport.maxsize"; int valueDefault = 100; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportMaxSize = value; } { String key = "monitor.winevent.forwarding.transport.maxtries"; int valueDefault = 900; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportMaxTries = value; } { String key = "monitor.winevent.forwarding.transport.interval.size"; int valueDefault = 15; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportIntervalSize = value; } { String key = "monitor.winevent.forwarding.transport.interval.msec"; long valueDefault = 1000L; String str = AgentProperties.getProperty(key); long value = valueDefault; try { value = Long.parseLong(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportIntervalMSec = value; } _scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { private volatile int _count = 0; @Override public Thread newThread(Runnable r) { Thread t = new Thread(r, WinEventResultForwarder.class.getSimpleName() + _count++); t.setDaemon(true); return t; } }); if (_transportIntervalMSec != -1) { _scheduler.scheduleWithFixedDelay(new ScheduledTask(), 0, _transportIntervalMSec, TimeUnit.MILLISECONDS); } }
From source file:at.ac.univie.isc.asio.Asio.java
@Bean(destroyMethod = "shutdown") public ScheduledExecutorService workerPool() { final ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("asio-worker-%d").build(); final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(factory); final DelegatingSecurityContextScheduledExecutorService secured = new DelegatingSecurityContextScheduledExecutorService( executor);//from w w w .jav a 2 s . c o m return secured; }
From source file:password.pwm.svc.report.ReportService.java
@Override public void init(PwmApplication pwmApplication) throws PwmException { status = STATUS.OPENING;//from ww w . j a v a 2s . c o m this.pwmApplication = pwmApplication; if (pwmApplication.getApplicationMode() == PwmApplicationMode.READ_ONLY) { LOGGER.debug(PwmConstants.REPORTING_SESSION_LABEL, "application mode is read-only, will remain closed"); status = STATUS.CLOSED; return; } if (pwmApplication.getLocalDB() == null || LocalDB.Status.OPEN != pwmApplication.getLocalDB().status()) { LOGGER.debug(PwmConstants.REPORTING_SESSION_LABEL, "LocalDB is not open, will remain closed"); status = STATUS.CLOSED; return; } if (!pwmApplication.getConfig().readSettingAsBoolean(PwmSetting.REPORTING_ENABLE)) { LOGGER.debug(PwmConstants.REPORTING_SESSION_LABEL, "reporting module is not enabled, will remain closed"); status = STATUS.CLOSED; clear(); return; } try { userCacheService = new UserCacheService(); userCacheService.init(pwmApplication); } catch (Exception e) { LOGGER.error(PwmConstants.REPORTING_SESSION_LABEL, "unable to init cache service"); status = STATUS.CLOSED; return; } settings = ReportSettings.readSettingsFromConfig(pwmApplication.getConfig()); summaryData = ReportSummaryData.newSummaryData(settings.getTrackDays()); executorService = Executors.newSingleThreadScheduledExecutor( Helper.makePwmThreadFactory(Helper.makeThreadName(pwmApplication, this.getClass()) + "-", true)); String startupMsg = "report service started"; LOGGER.debug(startupMsg); executorService.submit(new InitializationTask()); status = STATUS.OPEN; }