public synchronized void publishMsgAsync()

in app/eventgenerator/src/main/java/com/googlecodesamples/cloud/jss/eventgenerator/service/EventPublisherService.java [72:91]


  public synchronized void publishMsgAsync(int threads, float runtime) {
    if ((executor != null && !executor.isTerminated()) || timer != null) {
      logger.warn("thread pool or timer already exist");
      return;
    }

    logger.info("settings for publishMsgAsync() threads: {}, runtime: {}", threads, runtime);

    if (runtime > 0) {
      // Start a timer to shut down the thread pool when runtime is up.
      timer = new Timer();
      timer.schedule(new TimeoutTask(this), (long) (runtime * 60 * 1000));
    }

    // Start a thread pool to execute the defined tasks.
    executor = Executors.newFixedThreadPool(threads);
    for (int i = 0; i < threads; i++) {
      executor.execute(new MessageTask(this));
    }
  }