JNDI error only hapenning in timer thread

L

Larry

I have a Struts/Hibernate application for which I run some "heartbeat"
processing, i.e. a thread which checks some things every minute. I
call java.util.Timer.scheduleAtFixedRate from my app's startup code to
set up this heartbeat thread. When I try to call the
org.hibernate.Transaction.beginTransaction() method inside the
heartbeat thread I get the error below, which indicates that Hibernate
is not able to find "comp/UserTransaction" in JNDI.

However, in other places in the application (i.e. code which is
executed a web request) the beginTransaction call works fine! It
seems there must be some difference in the environment between the
heartbeat thread and the rest of the app which is causing the JNDI
problem only in the heartbeat. Any ideas?

-------------------------------

2efc2efc JTATransactio E org.hibernate.transaction.JTATransaction
TRAS0014I: The following exception was logged
javax.naming.NameNotFoundException: Name "comp/UserTransaction" not
found in context "java:".
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.Throwable.<init>(Throwable.java)
at javax.naming.NamingException.<init>(NamingException.java:111)
at
com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1021)
at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:932)
at
com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1261)
at
com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:196)
at
com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:137)
at javax.naming.InitialContext.lookup(InitialContext.java:360)
at
org.hibernate.transaction.JTATransaction.<init>(JTATransaction.java:60)
at
org.hibernate.transaction.JTATransactionFactory.createTransaction(JTATransactionFactory.java:53)
at org.hibernate.jdbc.JDBCContext.getTransaction(JDBCContext.java:177)
at
org.hibernate.impl.SessionImpl.getTransaction(SessionImpl.java:1279)
at
org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1289)
at com.test.heartbeat.check.run(check.java:22)
at java.util.TimerThread.mainLoop(Timer.java:446)
at java.util.TimerThread.run(Timer.java:396)
 
J

JustTryItOn

Larry said:
I have a Struts/Hibernate application for which I run some "heartbeat"
processing, i.e. a thread which checks some things every minute. I
call java.util.Timer.scheduleAtFixedRate from my app's startup code to
set up this heartbeat thread. When I try to call the
org.hibernate.Transaction.beginTransaction() method inside the
heartbeat thread I get the error below, which indicates that Hibernate
is not able to find "comp/UserTransaction" in JNDI.

However, in other places in the application (i.e. code which is
executed a web request) the beginTransaction call works fine! It
seems there must be some difference in the environment between the
heartbeat thread and the rest of the app which is causing the JNDI
problem only in the heartbeat. Any ideas?

I've found something online that seems to indicate that there is indeed
an issue with accessing JNDI from timer thread.

I've come up with a solution to this problem... I have moved the work
that I was doing inside the heartbeat thread to a new request handler
(Action class), so it is now able to begin the transaction. To call
that new handler, I make an HTTP GET request from the heartbeat thread.

However, there still is an issue I'd like to resolve. The heartbeat
thread now needs to know the url associated with my new handler. Right
now I'm storing the url in appconfig.properties, including the port
number, which is a number that we may need to change for
implementations. Is there any way I can discover that port number on
my own? I see that the port is specified in "server.xml"... can I
somehow discover either the data from the file, or even the location of
the file itself, from my thread?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top