JBoss AS6 - WorkManager threads not able to lookup java:comp/UserTransaction or any ENC information.
vidy5300 Feb 8, 2011 2:05 PMI 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