我在JBoss EAP 6.0.1服务器上运行我的java应用程序,它在Windows服务器上作为服务运行。当我尝试从Services.msc停止JBoss服务时,某些用户正在访问我的
应用程序,我得到以下错误,当没有人使用该应用程序时,我没有看到错误:
2014-04-03 06:34:47,625 FATAL [DsConnPool] .getConnection():无法从java获取连接:myapp javax.resource.ResourceException:IJ000451:连接管理器已关闭:java:/ myapp
JNDI查找完成如下:
protected void connectToDS() throws NamingException,
javax.naming.CommunicationException
{
try{
javax.naming.Context ctx = new InitialContext( );
ds = ( DataSource )ctx.lookup( "java:/myapp");
}
standalone.xml文件中的数据源子系统如下:
<datasources>
<datasource jndi-name="java:/myapp" pool-name="myapp" enabled="true" use-java- context="true">
<connection-url>jdbc:sqlserver://localhost:9090;DatabaseName=myappdb</connection-url>
<driver>sqlserver</driver>
<new-connection-sql>select count(*) from emp</new-connection-sql>
<pool>
<min-pool-size>9</min-pool-size>
<max-pool-size>25</max-pool-size>
</pool>
<security>
<user-name>x</user-name>
<password>y</password>
</security>
<statement>
<prepared-statement-cache-size>100</prepared-statement-cache-size>
<share-prepared-statements>true</share-prepared-statements>
</statement>
</datasource>
DSConnPool类:
public Connection getConnection() throws SQLException
{
int CON_RETRY = 0;
int BADCON_RETRY = 1;
Connection con = null;
int i = 1;
int badcon = 0;
for( ; ; ++i )
{
try
{
con = ds.getConnection();
if( !checkConn( con ) )
{
++badConnections;
con.close();
if( ++badcon > BADCON_RETRIES )
throw new SQLException();
}
else
break;
}
catch( SQLException e )
{
if( i > GETCON_RETRIES )
{
Log.fatal( getClass().getName(), ".getConnection()", "unable to get connection from " + datasource, e.getMessage() );
throw e;
}
}
}
我的代码中的所有数据库连接都已关闭。如何解决此错误,我是否缺少任何配置?