11 Replies Latest reply on Feb 11, 2011 1:09 PM by jaikiran

    JBoss AS6 - WorkManager threads not able to lookup java:comp/UserTransaction or any ENC information.

    vidy5300

      I have this simple code which shows the problem.

      public class JBossServletContextListener implements ServletContextListener

      {

          public void contextDestroyed(ServletContextEvent arg0)

          {

              System.out.println("Going to destroy");

          }

       

          public void contextInitialized(ServletContextEvent arg0)

          {

              System.out.println("App Context Initialized");

              InitialContext context;

              try

              {

                  context = new InitialContext();

                  DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/fleetcycle");

                  System.out.println("jboss5ServletListener app - jndi look up from ENC successful");

       

                  UserTransaction ut = (UserTransaction) context.lookup("java:comp/UserTransaction");

                  System.out.println("jboss5ServletListener app - jndi look up from ENC successful" + ut);

       

                  executeInAnotherThread();

       

              } catch (NamingException e)

              {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

              }

       

          }

       

          private void executeInAnotherThread()

          {

              WorkManager workManager = null;

              try

              {

                  MBeanServer server = MBeanServerLocator.locateJBoss();

                  workManager = (WorkManager) server.getAttribute(new ObjectName(

                          "jboss.jca:service=WorkManager"), "Instance");

              } catch (MalformedObjectNameException e)

              {

                  // TODO

              } catch (Exception e)

              {

                  // TODO

              }

              try

              {

                  workManager.doWork(new Work() {

                     

                      @Override

                      public void run()

                      {

                          try

                          {

                              InitialContext context = new InitialContext();

                              DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/fleetcycle");

                              System.out.println("jboss5ServletListener workmanager - jndi look up from ENC successful" + ds);

       

                              UserTransaction ut = (UserTransaction) context.lookup("java:comp/UserTransaction");

                              System.out.println("jboss5ServletListener workmanager - jndi look up from ENC successful" + ut);

                          } catch (NamingException e)

                          {

                              // TODO Auto-generated catch block

                              e.printStackTrace();

                          }

                         

                      }

                     

                      @Override

                      public void release()

                      {

                          // TODO Auto-generated method stub

                         

                      }

                  });

              } catch (WorkException e)

              {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

              }

          }

       

      }

       

       

      When I run this in JBoss AS 6, the main thread is able to look up data from ENC, but the work manager thread is not able to. Here is the exception I get.

      11:28:56,718 INFO  [TomcatDeployment] deploy, ctxPath=/threadJbossServletListener

      11:28:56,734 INFO  [STDOUT] jboss6ServletListener app - App Context Initialized

      11:28:56,734 INFO  [STDOUT] jboss6ServletListener app - jndi look up from ENC successfulorg.jboss.resource.adapter.jdbc.WrapperDataSource@d2f353

      11:28:56,734 INFO  [STDOUT] jboss6ServletListener app - jndi look up from ENC successfulorg.jboss.tm.usertx.client.ServerVMClientUserTransaction@ce4625

      11:28:56,765 ERROR [STDERR] javax.naming.NameNotFoundException: env not bound

      11:28:56,765 ERROR [STDERR]             at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)

      11:28:56,765 ERROR [STDERR]             at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)

      11:28:56,765 ERROR [STDERR]             at org.jnp.server.NamingServer.getObject(NamingServer.java:785)

      11:28:56,765 ERROR [STDERR]             at org.jnp.server.NamingServer.lookup(NamingServer.java:396)

      11:28:56,765 ERROR [STDERR]             at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:728)

      11:28:56,765 ERROR [STDERR]             at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:835)

      11:28:56,765 ERROR [STDERR]             at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688)

      11:28:56,765 ERROR [STDERR]             at javax.naming.InitialContext.lookup(InitialContext.java:392)

      11:28:56,765 ERROR [STDERR]             at com.test.JBossServletContextListener$1.run(JBossServletContextListener.java:80)

      11:28:56,765 ERROR [STDERR]             at org.jboss.resource.work.WorkWrapper.run(WorkWrapper.java:172)

      11:28:56,765 ERROR [STDERR]             at org.jboss.threads.SimpleDirectExecutor.execute(SimpleDirectExecutor.java:33)

      11:28:56,765 ERROR [STDERR]             at org.jboss.threads.QueueExecutor.runTask(QueueExecutor.java:801)

      11:28:56,765 ERROR [STDERR]             at org.jboss.threads.QueueExecutor.access$100(QueueExecutor.java:45)

      11:28:56,765 ERROR [STDERR]             at org.jboss.threads.QueueExecutor$Worker.run(QueueExecutor.java:821)

      11:28:56,765 ERROR [STDERR]             at java.lang.Thread.run(Thread.java:662)

      11:28:56,765 ERROR [STDERR]             at org.jboss.threads.JBossThread.run(JBossThread.java:122)

      11:28:56,796 INFO  [service] Removing bootstrap log handlers

      11:28:56,890 INFO  [org.apache.coyote.http11.Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8080

       

       

      The same thing works in JBoss 5.1.0 GA. Here is the output from Jboss 5.1.0 GA. Is there a work around for this?

       

      11:21:23,038 INFO  [TomcatDeployment] deploy, ctxPath=/threadJbossServletListener

      11:21:23,054 INFO  [STDOUT] App Context Initialized

      11:21:23,054 INFO  [STDOUT] jboss5ServletListener app - jndi look up from ENC successful

      11:21:23,054 INFO  [STDOUT] jboss5ServletListener app - jndi look up from ENC successfulorg.jboss.tm.usertx.client.ServerVMClientUserTransaction@5673b3

      11:21:23,069 INFO  [STDOUT] jboss5ServletListener workmanager - jndi look up from ENC successfulorg.jboss.resource.adapter.jdbc.WrapperDataSource@9498a3

      11:21:23,069 INFO  [STDOUT] jboss5ServletListener workmanager - jndi look up from ENC successfulorg.jboss.tm.usertx.client.ServerVMClientUserTransaction@5673b3

      11:21:23,116 INFO  [Http11Protocol] Starting Coyote HTTP/1.1 on http-0.0.0.0-8080

       

      I have attached the war file for JBoss 6.0.0. Final that shows the problem

        • 1. JBoss AS6 - WorkManager threads not able to lookup java:comp/UserTransaction or any ENC information.
          vidy5300

          Has anyone seen this issue? How did you solve it? Please let me know. Our application is heavily doing multithreading and needs handle to userTransaction to perform database transactions. We are looking to updated from Jboss 5 to Jboss 6

          • 2. JBoss AS6 - WorkManager threads not able to lookup java:comp/UserTransaction or any ENC information.
            jaikiran

            The spec doesn't say anything about ENC access from a Work created out of WorkManager. Why do you want to use the ENC of the servlet in the Work? Why not use the non-ENC jndi context (ex: java:DefaultDS for that datasource)?

            • 3. JBoss AS6 - WorkManager threads not able to lookup java:comp/UserTransaction or any ENC information.
              vidy5300

              Jaikiran,

               

              Non ENC also does not work, I tried to look up java:comp/UserTransaction. That also does not work. And container managed transaction is something we use to access database. My main concern is the user transaction, the other not a big deal.

               

              Thank you

              Viji

              • 4. JBoss AS6 - WorkManager threads not able to lookup java:comp/UserTransaction or any ENC information.
                jaikiran

                java:comp is ENC.

                 

                Try java:UserTransaction.

                • 5. Re: JBoss AS6 - WorkManager threads not able to lookup java:comp/UserTransaction or any ENC information.
                  vidy5300

                  Hi Jaikiran,


                  I tried java:UserTransaction, java/UserTransaction. The look up for these failed in the main thread itself, ofcourse it did fail in the workmanager threads as well. This is the stack trace from the main thread.

                   

                  javax.naming.NameNotFoundException: UserTransaction not bound
                  at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
                  at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)
                  at org.jnp.server.NamingServer.getObject(NamingServer.java:785)
                  at org.jnp.server.NamingServer.lookup(NamingServer.java:443)
                  at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:728)
                  at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688)
                  at javax.naming.InitialContext.lookup(InitialContext.java:392)
                  at com.test.ThreadJBoss6.initialize(ThreadJBoss6.java:39)
                  at org.apache.jsp.index_jsp._jspService(index_jsp.java:63)
                  at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
                  at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
                  at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
                  at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326)
                  at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)
                  at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
                  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324)
                  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)
                  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
                  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                  at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181)
                  at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285)
                  at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261)
                  at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88)
                  at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100)
                  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                  at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
                  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                  at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53)
                  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)
                  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
                  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654)
                  at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951)
                  at java.lang.Thread.run(Thread.java:662)


                          InitialContext context;
                          try
                          {
                              context = new InitialContext();
                              try
                              {
                               //FAILED - EXCEPTION SHOWN ABOVE IN THE MAIN THREAD ITSELF
                                  UserTransaction ut = (UserTransaction) context.lookup("java:/UserTransaction");
                                  System.out.println("threadJBoss6 app - jndi look up successful" + ut);
                              }
                              catch(Exception e1)
                              {
                                  e1.printStackTrace();
                                  try
                                  {
                                      //FAILED - EXCEPTION SHOWN ABOVE IN THE MAIN THREAD ITSELF

                                      UserTransaction ut = (UserTransaction) context.lookup("java:UserTransaction");
                                      System.out.println("catch 1 threadJBoss6 app - jndi look up successful" + ut);
                                  }
                                  catch(Exception e2)
                                  {
                                      e2.printStackTrace();
                                      //WORKED IN MAIN THREAD, BUT FAILS IN THE WORK MANAGER THREAD CALL BELOW
                                      UserTransaction ut = (UserTransaction) context.lookup("java:comp/UserTransaction");
                                      System.out.println("catch 2 threadJBoss6 app - jndi look up successful" + ut);
                                  }
                              }

                       //Work manager threads are created in this function.
                              executeInAnotherThread();

                   

                  Thank you

                  Viji

                  • 6. Re: JBoss AS6 - WorkManager threads not able to lookup java:comp/UserTransaction or any ENC information.
                    jaikiran
                    Try java:UserTransaction.

                    I'm sorry, it should have been just UserTransaction without the java: prefix:

                     

                    UserTransaction ut = (UserTransaction) context.lookup("UserTransaction");

                    • 7. Re: JBoss AS6 - WorkManager threads not able to lookup java:comp/UserTransaction or any ENC information.
                      vidy5300

                      Thanks Jaikiran, that worked.

                      • 8. Re: JBoss AS6 - WorkManager threads not able to lookup java:comp/UserTransaction or any ENC information.
                        kccoyote

                        So is there something we're missing here?

                         

                        java:comp/UserTransaction used to work right up until the final version of JBoss6 -- I know because we used it just fine in the CR's until Final got released.

                         

                        We have a war that deploys to different containers and JBoss is the only one who requires us to look up UserTransaction instead of java:comp/UserTransaction. What's the reason behind this?

                         

                        It's especially bothersome because we use a third party library that looks up the UserTransaction object with java:comp/UserTransaction.

                        • 9. Re: JBoss AS6 - WorkManager threads not able to lookup java:comp/UserTransaction or any ENC information.
                          jaikiran

                          kccoyote wrote:

                           

                           

                           

                          java:comp/UserTransaction used to work right up until the final version of JBoss6 -- I know because we used it just fine in the CR's until Final got released.

                           

                          We have a war that deploys to different containers and JBoss is the only one who requires us to look up UserTransaction instead of java:comp/UserTransaction. What's the reason behind this?

                           

                          Where are you using the java:comp lookup from? What class is it? From what I see in the spec, it doesn't talk about access to java:comp environment in a Work triggered by a WorkerManager.

                          • 10. Re: JBoss AS6 - WorkManager threads not able to lookup java:comp/UserTransaction or any ENC information.
                            vidy5300

                            Yes i agree with kccoyote. java:comp/UserTransaction used to work just fine in new worker threads in Jboss 5. Our applicaiton also has to run on different containers and all other containers provide support for usage of java:comp/UserTransaction in a newly spawned worker thread. Now for Jboss AS 6 alone we have to do special configuration.

                             

                            In our case the java:comp/UserTransaction is attained by hibernate class org.hibernate.transaction.JTATransactionFactory (http://kickjava.com/src/org/hibernate/transaction/JTATransactionFactory.java.htm). The default look up is java:comp/UserTransaction. Hibernate does provide a property to override this look up name. So now we are left with adding this property only for Jboss AS 6 and not for other containers if we choose to upgrade from 5 to 6.

                            • 11. Re: JBoss AS6 - WorkManager threads not able to lookup java:comp/UserTransaction or any ENC information.
                              jaikiran

                              Viji V wrote:

                               

                              Yes i agree with kccoyote. java:comp/UserTransaction used to work just fine in new worker threads in Jboss 5.

                              It probably might have worked, I am not saying it didn't.

                               

                               

                              Viji V wrote:

                               

                                Our applicaiton also has to run on different containers and all other containers provide support for usage of java:comp/UserTransaction in a newly spawned worker thread. Now for Jboss AS 6 alone we have to do special configuration.

                               

                              In our case the java:comp/UserTransaction is attained by hibernate class org.hibernate.transaction.JTATransactionFactory (http://kickjava.com/src/org/hibernate/transaction/JTATransactionFactory.java.htm). The default look up is java:comp/UserTransaction. Hibernate does provide a property to override this look up name. So now we are left with adding this property only for Jboss AS 6 and not for other containers if we choose to upgrade from 5 to 6.

                              Like I have already said, I haven't seen anything in the spec which says that this should work. I might have missed some section though. So if you or someone can point me to a section which shows that this should work as per the spec, then yes it's a bug which needs to be fixed.