* The scheduling is done based on intervalType please review the
* simulation plan for the timing.
*/
private void runThreadedSimulation(SimulationPlan plan) {
this.initializeMetricsServer(plan);
final ConsoleReporter consoleReporter = createConsoleReporter(metrics, plan.getMetricsReportInterval());
final ScheduledExecutorService aggregators = Executors.newScheduledThreadPool(1, new SimulatorThreadFactory());
final ScheduledExecutorService collectors = Executors.newScheduledThreadPool(
plan.getNumMeasurementCollectors(), new SimulatorThreadFactory());
final ExecutorService aggregationQueue = Executors.newSingleThreadExecutor(new SimulatorThreadFactory());
final ScheduledExecutorService readers = Executors.newScheduledThreadPool(plan.getReaderThreadPoolSize(),
new SimulatorThreadFactory());
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
shutdown(collectors, "collectors", 5);
shutdown(readers, "readers", 5);
shutdown(aggregators, "aggregators", 1);
shutdown(aggregationQueue, "aggregationQueue", Integer.MAX_VALUE);
metricsServer.shutdown();
log.info("Wait for console reporter...");
try {
Thread.sleep(181000);
} catch (InterruptedException e) {
}
consoleReporter.stop();
}
});
MeasurementAggregator measurementAggregator = new MeasurementAggregator(metricsServer, this, metrics,
aggregationQueue, plan.getNumMeasurementCollectors() * plan.getBatchSize());