6 Replies Latest reply on Jun 22, 2011 9:50 PM by Benniu Ji

    How to persist an object in Asynchronous method in a cron job

    Benniu Ji Newbie

      I tried to persist an object in an Asynchronous method, but it failed.

      public void schedule(@Observes @Every(nth=10, value=Interval.SECOND) Trigger t){
          for (TestRunner runner: pendingRunners){
           Executor e = new Executor();

      @Transactional @Dependent
      public class Executor implements Serializable {
           private static final long serialVersionUID = 5413892488805663161L;
           EntityManager em;
           public void run(TestRunner runner){
                try {
                     TestAgent agent = runner.getTestAgent();
                     if (agent!=null){
                                      runner.setStartTime(new Date());
                          //Call STAF lib to run test script
                                      runner.setStopTime(new Date());
                } catch (Exception e) {
                     // TODO Auto-generated catch block

      After running the cron job, I got following error:

      17:28:06,279 ERROR [STDERR] java.lang.NullPointerException

      It seems entitymanager is null.
      Can anyone help on this?