`

WebSphere下发布定时程序,无法取得数据源连接

阅读更多

一个web应用程序,里面加了一个定时任务,任务中有取数据库连接的语句,是采用数据源的方式。在tomcat下是完全可以用的。但是在was上发布后,手动操作的可以正常连接数据库执行操作。定时任务使用的是同样的代码,就是报

javax.naming.ConfigurationException:
 A JNDI operation on a "java:" name cannot be completed because the serverruntime is not able to associate the operation's thread with any J2EE application component.  
This condition can occur when the JNDI client using the "java:" name is not executed on the thread of a server application request.  
Make sure that a J2EE application does not execute JNDI operations on "java:" names within static code blocks or in threads created by that J2EE application.  
Such code does not necessarily run on the thread of a server application request and therefore is not supported by JNDI operations on "java:" names.
 [Root exception is javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".]

 查资料才了解到

那个定时的程序,在was上执行的时候用ctx.lookup("java:comp/env/DSsystem")取不到数据源.用ctx.lookup("jdbc/DSsystem")这个可以。

 

定时任务不能取到数据源是因为定时任务是单独起了一个线程,在was中,这个单独的线程不受系统jndi的管理,多以在这个单独起的线程里不能从jndi取。但是可以直接用ctx.lookup("jdbc/DSsystem")。

 

 

下面拷贝一段网上的问题描述和回复

Problem
A JNDI operation on a "java:" name must be performed on the thread of a server application request
User response
Make sure that a J2EE application does not execute JNDI operations on "java:" names within static code blocks or in threads created by that J2EE application. Such code does not necessarily run on the thread of a server application request and therefore is not supported by JNDI operations on "java:" names.

分享到:
评论
2 楼 xiaoxin 2009-08-21  
不好意思写错了,我已经修改了,在was上执行的时候用ctx.lookup("java:comp/env/DSsystem")取不到数据源。

看来您知道怎么写是对的,希望赐教。
1 楼 魔力猫咪 2009-08-15  
请问你在Websphere中的Web应用程序也使用的是("java:comp/env/jdbc/DSsystem")这样的JNDI名吗?
其实你这个问题只是因为你JNDI名写错了而已。因为不同的JavaEE服务器对JNDI的命名规则是不一样的。Glassfish上的缺省JNDI名和JBoss上的完全不一样。
听说6.0规范中将对这个问题进行规范,统一规定名称规格。

相关推荐

Global site tag (gtag.js) - Google Analytics