Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JNDI resource not available for servlet loaded on startup

91 views
Skip to first unread message

WebSphere newbie

unread,
Mar 2, 2006, 10:31:37 AM3/2/06
to
I'm runnig WebSphere 5.1 trial.

I configured my web application to access the database using WebSphere
JDBC provider.
It works for all servlets except one that is loaded on startup an get
the following error:

javax.naming.NameNotFoundException: Name comp/env/jdbc not found in
context "java:".
at
com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1663)
at
com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1009)
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:194)
at
com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:135)
at javax.naming.InitialContext.lookup(InitialContext.java:360)

All other servlets work well and if I remove the load-on-startup option
in web.xml and manually call the same servlet it works without any problem.

Hints?

Thanks.

A WebSphere newbie.

Cyrille Le Clerc

unread,
Mar 3, 2006, 9:55:24 AM3/3/06
to
Hi,

Do you perform your jndi lookup from an application created thread
or from the Websphere created thread ?

It is not possible to lookup "java:comp/env/" namespace from an
application created thread.

Cyrille

--
Cyrille Le Clerc
cyrille...@pobox.com
cyrille...@fr.ibm.com

WebSphere newbie

unread,
Mar 3, 2006, 1:23:05 PM3/3/06
to
Cyrille Le Clerc ha scritto:

> Hi,
>
> Do you perform your jndi lookup from an application created thread
> or from the Websphere created thread ?
>
> It is not possible to lookup "java:comp/env/" namespace from an
> application created thread.
>
Thanks for the answer.

Yes, it is an application created thread. Why there is such limitation?
Is it a policy setting? Can I change it?
Can you point me to some documentation about this?

Again, thank you very much.

A WebSphere newbie.

WebSphere newbie

unread,
Mar 3, 2006, 4:58:21 PM3/3/06
to
WebSphere newbie ha scritto:

> All other servlets work well and if I remove the load-on-startup option
> in web.xml and manually call the same servlet it works without any problem.
>
This is not really true.
After Cyrille reply I found there are other servlets failing and that
the one I was supposing was failing because the load on startup option
doesnt' really work even when this option was removed (I don' know why I
didn't notice that before).
Again, congratulations to who found the problem even with a misleading
description :-)
However the problem is still open and I'm still looking for a solution.
I don't want to rewrite all those servlets, suggestions are welcome.

Thanks

A WebSphere newbie.

Cyrille Le Clerc

unread,
Mar 6, 2006, 5:41:18 AM3/6/06
to
Hi,

WHY LOOKUPS ON "JAVA:COMP/ENV" DON'T WORK ON APPLICATION CREATED THREAD
?

Your problem is a "work as design" feature of Websphere.

Websphere does not allow to do a "java:comp/env/..." jndi lookup
from an application created thread.

All this is explained in two technotes :
- Technote 1168795 : "NameNotFoundException when an EJB lookup is
requested"
-> http://www-1.ibm.com/support/docview.wss?uid=swg21168795
- Technote 1168795 : "InitialContext in a servlet or JSP, threads
created by the servlet or JSP fail with a noThreadContext message and a
nullPointerException."
-> http://www-1.ibm.com/support/docview.wss?uid=swg21175742

Here is an extract of a technote :
"Do not execute the look-up in a separate thread. There is no way to
provide a spun-off thread in any context. So, generally speaking, the
code must be modified so that it does not do the java: look-up from a
thread that you spin off."

WORKAROUNDS

* The main workaround is refactor your code and perform the jndi lookup
on a Websphere Created thread (ie Servlet or ServletContextListener
thread).
- Pros :
-> Websphere's best practice
- Cons :
-> code refactoring can be important

* Another workaround, but an extremely inadvisable one, is to jndi
lookup on "jdbc/myDataSource" without the "java:comp/env" prefix.
- Pros :
-> no code refactoring, just a change of the config config
- Cons :
-> in Websphere 6+, logs will be flooded by "J2CA0294W:
Deprecated usage of direct JNDI lookup of resource"
-> you loose the "<res-sharing-scope>" behavior that is defined
in you web.xml (or ejb-jar.xml)

* Yet another workaround, switch to an external production ready
DataSource (e.g. Jakarta DBCP, C3P0, ...)
- Pros :
-> simple data sources are simple to configure and may fit your
requirements (perf, config, ...)
- Cons :
-> You may want to manage your data source in the application
server config
-> you loose Websphere monitoring (Tivoli Performance Viewer)

Hope this helps,

0 new messages