Example usage for java.util.concurrent ScheduledThreadPoolExecutor ScheduledThreadPoolExecutor

List of usage examples for java.util.concurrent ScheduledThreadPoolExecutor ScheduledThreadPoolExecutor

Introduction

In this page you can find the example usage for java.util.concurrent ScheduledThreadPoolExecutor ScheduledThreadPoolExecutor.

Prototype

public ScheduledThreadPoolExecutor(int corePoolSize) 

Source Link

Document

Creates a new ScheduledThreadPoolExecutor with the given core pool size.

Usage

From source file:com.fusesource.forge.jmstest.executor.TerminatingThreadPoolExecutor.java

private void startChecker() {
    scheduledChecker = new ScheduledThreadPoolExecutor(1);
    scheduledChecker.scheduleAtFixedRate(new Runnable() {

        public void run() {
            log().debug("Checking Terminate condition for " + getName());
            long currentTime = System.currentTimeMillis();
            if (getActiveCount() == 0) {
                if (currentTime - lastSubmit.get() >= getKeepAliveTime(TimeUnit.MILLISECONDS)) {
                    log().debug("Shutting down...");
                    shutdown();//from ww w . j a v  a  2s  .c om
                }
            }
        }
    }, getKeepAliveTime(TimeUnit.NANOSECONDS), getKeepAliveTime(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS);

}

From source file:greenapi.ui.charts.ChartPanelSupport.java

public ChartPanelSupport(String title, String axisLabel, T resource, int updateIntervalInSeconds) {
    this.title = title;
    this.axisLabel = axisLabel;
    this.resource = resource;
    this.updateDelayInSeconds = updateIntervalInSeconds;

    this.chartPanel = new org.jfree.chart.ChartPanel(chart = this.createChart());
    this.chartPanel.setDomainZoomable(true);
    this.chartPanel.setRangeZoomable(true);

    setLayout(new BoxLayout(this, 2));
    this.add(this.chartPanel);

    updateChartExecutorService = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors());
}

From source file:com.fusesource.forge.jmstest.executor.BenchmarkController.java

@Override
synchronized public void stop() {

    coordinator.release();/*  w  ww  .j a  v  a2 s  . co m*/
    super.stop();

    log().info("BenchmarkController going down in 5 Seconds");

    final CountDownLatch brokerStopLatch = new CountDownLatch(1);
    final ScheduledThreadPoolExecutor waiter = new ScheduledThreadPoolExecutor(1);
    waiter.schedule(new Runnable() {
        public void run() {
            brokerStopLatch.countDown();
            waiter.shutdown();
        }
    }, 5, TimeUnit.SECONDS);

    try {
        brokerStopLatch.await();
    } catch (InterruptedException e1) {
    }

    if (broker != null) {
        log().info("Stopping embedded broker for Benchmark framework: ");
        try {
            broker.stop();
        } catch (Exception e) {
            // log().error("Embedded broker could not be stopped.", e);
        }
    }
}

From source file:org.trustedanalytics.platformoperations.ApplicationConfiguration.java

@Bean
public ScheduledThreadPoolExecutor scheduledExecutorService() {
    return new ScheduledThreadPoolExecutor(4);
}

From source file:org.apache.hadoop.hbase.crosssite.verifier.CSBTClusterVerifier.java

public CSBTClusterVerifier(Configuration conf) {
    super(conf);/* www  .j  av a  2  s .  c  o m*/
    int numThreads = conf.getInt("hbase.crosssite.verifier.numthreads", MAX_NUM_THREADS);
    executor = new ScheduledThreadPoolExecutor(numThreads);
}

From source file:org.rifidi.edge.core.sensors.sessions.AbstractSerialSensorSession.java

@Override
protected void _connect() throws IOException {
    this.setStatus(SessionStatus.CONNECTING);
    if (processing.get()) {
        if (!processing.compareAndSet(true, false)) {
            logger.warn("Killed a non active executor. " + "That should not happen. ");
        }//  w  w  w. j a  v  a 2s.  c  o  m
        // TODO: better would be to have a method in
        // AbstractSensorSession that handles the shutdown of the
        // executor
        executor.shutdownNow();
        executor = null;
        resetCommands();
    }
    boolean success = true;
    try {
        this.connectSerial(commPortName);
    } catch (Exception e) {
        success = false;
        this.setStatus(SessionStatus.CLOSED);
        throw new IOException(e.getMessage());
    }
    executor = new ScheduledThreadPoolExecutor(1);
    if (success) {
        processing.compareAndSet(false, true);
        this.setStatus(SessionStatus.PROCESSING);
    }
}

From source file:wattsup.jsdk.ui.ChartPanelSupport.java

/**
 * //from   ww  w .  j a  v a2 s. c o m
 * @param title
 *            The title of the chart.
 * @param axisLabel
 *            The axis label.
 * @param data
 *            The data repository for the chart. Might not be <code>null</code>.
 * @param updateIntervalInSeconds
 *            The interval in seconds to update the chart.
 */
public ChartPanelSupport(String title, String axisLabel, T data, int updateIntervalInSeconds) {
    this.title_ = title;
    this.axisLabel_ = axisLabel;
    this.data_ = data;
    this.updateDelayInSeconds_ = updateIntervalInSeconds;

    chart_ = this.createChart();
    this.chartPanel_ = new org.jfree.chart.ChartPanel(chart_);
    this.chartPanel_.setDomainZoomable(true);
    this.chartPanel_.setRangeZoomable(true);

    setLayout(new BoxLayout(this, 2));
    this.add(this.chartPanel_);

    updateChartExecutorService_ = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors());
}

From source file:com.fusesource.forge.jmstest.executor.BenchmarkValueRecorder.java

@Override
protected void createHandlerChain() {
    super.createHandlerChain();

    getConnector().addHandler(new DefaultCommandHandler() {
        public boolean handleCommand(BenchmarkCommand command) {
            switch (command.getCommandType()) {
            case CommandTypes.PREPARE_BENCHMARK:
                PrepareBenchmarkCommand prepCmd = (PrepareBenchmarkCommand) command;
                File benchmarkDir = getBenchmarkWorkDirectory(prepCmd.getBenchmarkConfig().getBenchmarkId());
                try {
                    FileUtils.deleteDirectory(benchmarkDir);
                    benchmarkDir.mkdirs();
                } catch (IOException e) {
                    log().error("Error creating directory : " + benchmarkDir.getAbsolutePath(), e);
                    e.printStackTrace();
                }/*  w  ww .  j av a2  s. c o m*/
                return true;
            case CommandTypes.REPORT_STATS:
                ReportStatsCommand stats = (ReportStatsCommand) command;
                recordStats(stats);
                return true;
            case CommandTypes.END_BENCHMARK:
                EndBenchmarkCommand endCommand = (EndBenchmarkCommand) command;
                final String benchmarkId = endCommand.getBenchmarkId();
                final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
                executor.schedule(new Runnable() {
                    public void run() {
                        for (BenchmarkPostProcessor processor : getPostProcessors()) {
                            processor.resetStatistics();
                            processor.setWorkDir(getBenchmarkWorkDirectory(benchmarkId));
                            processor.processData();
                        }
                        executor.shutdown();
                    }
                }, 5, TimeUnit.SECONDS);
                return true;
            default:
                return false;
            }
        }
    });
}

From source file:org.atricore.idbus.capabilities.sts.main.WSTSecurityTokenService.java

public void init() {
    tokenMonitor = new TokenMonitor(this, getTokenMonitorInterval());

    stpe = new ScheduledThreadPoolExecutor(3);
    stpe.scheduleAtFixedRate(tokenMonitor, getTokenMonitorInterval(), getTokenMonitorInterval(),
            TimeUnit.MILLISECONDS);

    // Register sessions in security domain !
    logger.info("[initialize()] : WST Security Token Service =" + getName());

}

From source file:gemlite.core.internal.measurement.MeasureHelper.java

public final static void init() {
    monitorTask = new MeasureMonitorTask();
    monitorTask.start();/*from  w  w  w .  ja v  a 2  s . c  o m*/
    scheduledService = new ScheduledThreadPoolExecutor(1);
    tpsTask = new MeasureTPSTask();
    scheduledService.scheduleWithFixedDelay(tpsTask, 1, 2, TimeUnit.SECONDS);
    if (LogUtil.getCoreLog().isInfoEnabled())
        LogUtil.getCoreLog().info("Measure monitor task started.");
}