2 Replies Latest reply on Oct 9, 2013 11:23 AM by Chris Ritchie

    Accessing ManagedThreadFactory via @Resource and JNDI

    Chris Ritchie Newbie

      Hi, I am trying to access a ManagedThreadFactory using @Resource. Here is what I have:

       

      @Stateless
      public class ReportBean {
      
          @Resource(name="myManagedThreadFactory")
          private ManagedThreadFactory threadFactory;
      
          public void runReports() {
               ReportTask reportTask = new ReportTask();
               Thread thread = threadFactory.newThread(reportTask);
               thread.start();
          }
      }
      
      

       

       

      And in the standalone.xml within the ee subsystem:

       

      <concurrent>
          <default-context-service/>
          <default-managed-thread-factory/>
          <default-managed-executor-service hung-task-threshold="60000" core-threads="5" max-threads="25" keepalive-time="5000"/>
          <default-managed-scheduled-executor-service hung-task-threshold="60000" core-threads="2" keepalive-time="3000"/>
          <managed-thread-factories>
              <managed-thread-factory name="myManagedThreadFactory" priority="1"/>
          </managed-thread-factories>
      </concurrent>
      
      

       

       

      I have tried all sorts of variations including these below, but I can't get it to inject my managed thread factory defined above.

       

      @Resource(lookup="myManagedThreadFactory")
      @Resource(name="java:comp/myManagedThreadFactory")
      @Resource(lookup="java:global/myManagedThreadFactory")
      
      

       

      I actually thought that this was working but realised that if an invalid name attribute is passed through to @Resource, then the default ManagedThreadFactory is used, with out any errors being displayed. Is this the correct behaviour? What do I need to do to inject my own ManagedThreadFactory.

       

      Thanks in advance,

       

      Chris