title: Spring State Machine task execution not firing
body: <p>I am having issues with getting a runnable to run in the manner described in the following reference:</p>
  
  <p><a href="http://docs.spring.io/autorepo/docs/spring-statemachine/1.0.0.M3/reference/htmlsingle/#statemachine-examples-tasks" rel="nofollow">http://docs.spring.io/autorepo/docs/spring-statemachine/1.0.0.M3/reference/htmlsingle/#statemachine-examples-tasks</a></p>
  
  <pre><code>TasksHandler handler = TasksHandler.builder()
      .task("1", sleepRunnable())
      .task("2", sleepRunnable())
      .task("3", sleepRunnable())
      .build();
  handler.runTasks();
  </code></pre>
  
  <p>My implementation looks like this:</p>
  
  <pre><code>private Action&lt;States, Events&gt; getUnlockedAction() {
      return new Action() {
          @Override
          public void execute(StateContext sc) {
              System.out.println("in action..");
              handler = new TasksHandler.Builder().taskExecutor(taskExecutor()).task("1", dp.runProcess(1)).build();
              handler.addTasksListener(new MyTasksListener());
  
              handler.runTasks();
  
              System.out.println("after action..");
          }
  
      };
  }
  </code></pre>
  
  <p>The initialization for the TaskExecutor looks like this: </p>
  
  <pre><code>    @Bean
  public TaskExecutor taskExecutor() {
      ThreadPoolTaskExecutor te = new ThreadPoolTaskExecutor();
      te.setMaxPoolSize(50);
      te.setThreadNamePrefix("LULExecutor-");
      te.setCorePoolSize(25);
      te.initialize();
      return te;
  }
  </code></pre>
  
  <p>My code for dp (DataProcessor) looks like this:</p>
  
  <pre><code>@Component
  @Qualifier("dataProcessor")
  public class ADataProcessor {
  
      public Runnable runProcess(final int i) {
      return new Runnable() {
          @Async
          @Override
          public void run() {
              long delay = (long) ((Math.random() * 10) + 1) * 1000;
              System.out.println("In thread " + i + "... sleep for " + delay);
              try {
                  Thread.sleep(delay);
              } catch (InterruptedException ex) {
                  Logger.getLogger(FSMFactoryConfig.class.getName()).log(Level.SEVERE, null, ex);
              }
              System.out.println("After thread " + i + "...");
          }
  
      };
      }
  }
  </code></pre>
  
  <p>When i execute my code, I see the messages for 'in action..' and 'after action..' with no delay..</p>
  
  <p>When I use the following: </p>
  
  <pre><code>                taskExecutor().execute(dp.runProcess(1));
              taskExecutor().execute(dp.runProcess(2));
              taskExecutor().execute(dp.runProcess(3));
              taskExecutor().execute(dp.runProcess(4));
              taskExecutor().execute(dp.runProcess(5));
              taskExecutor().execute(dp.runProcess(6));
  </code></pre>
  
  <p>I get what I would expect from using the TasksHandler..</p>
  
  <ul>
  <li>state changed to UNLOCKED</li>
  <li>In thread 2... sleep for 10000</li>
  <li>In thread 3... sleep for 5000</li>
  <li>In thread 4... sleep for 8000</li>
  <li>In thread 5... sleep for 4000</li>
  <li>In thread 6... sleep for 4000</li>
  <li>In thread 1... sleep for 9000</li>
  <li>Jan 13, 2016 12:32:13 PM - org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor initialize</li>
  <li>INFO: Initializing ExecutorService </li>
  <li>state changed to LOCKED</li>
  <li>After thread 5...</li>
  <li>After thread 6...</li>
  <li>After thread 3...</li>
  <li>After thread 4...</li>
  <li>After thread 1...</li>
  <li>After thread 2...</li>
  </ul>
  
  <p>None of the messages before or after the delay in the sleep are displayed when using the TasksHandler.  So my question, how do I actually execute my runnable??  If I'm doing it correctly, what should I check?</p>