2 Replies Latest reply on Jan 16, 2010 4:45 AM by kapitanpetko

    Nested Asynchronous Tasks

    jhollerer

      Hi,


      I have a lot of Background Tasks to be completed and therefore i want one instance to monitor all those Background Tasks!
      The monitoring Task is itself contains a @Asynchronous method !


      All is started by using Quartz !


      Within the MainBackgroundTask i then want to launch all the other Background tasks - which listen for external informations.


      My problem now is that the nested Tasks (which are started by the MainBackgroundTasks) do not get the EntityManager to insert the new information into the database.


      The MainBackgroundTask gets the EntityManager (as i read out of the Database which task to start) - and both Functions (which are triggered by Quartz) are configured the same - why is the nested Background task not getting the EntityManager  (its null) !


      The only difference between the MainBackgroundTask and the sub tasks is that the MainBackgroundTask is annotated with


      @Scope(ScopeType.APPLICATION)






          @Asynchronous
          @Transactional
          public QuartzTriggerHandle doMyJob(@IntervalDuration Long interval,int backgroundid){
             ..... getting my infos - and persist them ....
          }




      Can someone explain to me - why i do not get the EntityManager in that case - i cant make the sub's also ScopeType.Application??

        • 1. Re: Nested Asynchronous Tasks
          jhollerer

          What i found out was that if i make a new BackgorundTask().doMyJob(@Intervall....) then it does not work !
          If i instead use in the BackgroundMainTask an
          @In
          BackgroundThread background


          and then use


          background.doMyJob(....) - then i have an entity manager and everything works !


          • 2. Re: Nested Asynchronous Tasks
            kapitanpetko

            Right, for injection to work, your component has to be created by Seam, using new doesn't work. So you should use @In(create=true) or Component.getInstance(backgroundTask). Also be aware that calls to the same component are not intercepted.


            HTH