Topic: 谁解决过这样的问题?(快速多次调用后,WEBLOGIC 抛出 无可用JDBCRESOURCE 异常)

  Print this page

1.谁解决过这样的问题?(快速多次调用后,WEBLOGIC 抛出 无可用JDBCRESOURCE 异常) Copy to clipboard
Posted by: jameszhang
Posted on: 2003-03-06 10:52

我做了SESSIONBEAN+ADO访问数据的例子,在一个客户快速多次调用后,WEBLOGIC 抛出 无可用JDBCRESOURC 异常,不知道要调整WEBLOGIC,还是要自己写程序限制??谢谢好手帮忙!

2.Re:谁解决过这样的问题? [Re: jameszhang] Copy to clipboard
Posted by: youlq
Posted on: 2003-03-06 11:00

应该是调整Weblogic JDBC Pool size。

3.Re:谁解决过这样的问题? [Re: jameszhang] Copy to clipboard
Posted by: jameszhang
Posted on: 2003-03-06 11:59

调整WEBLOGIC JDBCSOURCE 后,情况好转,但还有极限,过极限就抛错

4.Re:谁解决过这样的问题? [Re: jameszhang] Copy to clipboard
Posted by: SimonLei
Posted on: 2003-03-06 12:26

jameszhang wrote:
调整WEBLOGIC JDBCSOURCE 后,情况好转,但还有极限,过极限就抛错


你的代码当中,使用完Connection之后,没有及时关闭。
这样就算把pool设得再大,都没有用的。

5.Re:谁解决过这样的问题? [Re: jameszhang] Copy to clipboard
Posted by: jameszhang
Posted on: 2003-03-06 14:04

那你看我这样关闭的是不是有错呢?另外如果我刷新的很慢,WEBLOGIC 是不抛出异常的,这点我刚才没有声明,请高手帮帮忙!!谢谢!

public class MyEJBBean implements SessionBean
{
SessionContext sessionContext;
private javax.sql.DataSource jdbcFactory;
private Connection connection=null;

public void ejbCreate() throws CreateException {
/**@todo Complete this method*/
Context c = null;
if (this.jdbcFactory == null) {
try {
c = new InitialContext();
this.jdbcFactory = (javax.sql.DataSource)
c.lookup("myData");
} catch (Exception e){ System.out.println("Error: " + e); }
}

}
public void ejbRemove()
{
/**@todo Complete this method*/
}
public void ejbActivate()
{
/**@todo Complete this method*/
}
public void ejbPassivate()
{
/**@todo Complete this method*/
}
public void setSessionContext(SessionContext sessionContext)
{
this.sessionContext = sessionContext;
}
//////////////////////////////////////////////////////////
private void getDBConnection() throws SQLException
{
try{
connection=this.jdbcFactory.getConnection();
}catch(Exception xxe)
{
System.out.println("getDBConnection Error :"+xxe);

}

}
///////////////////////////////////////////////////////
public int getCount()
{
int iRet=0;
try{
this.getDBConnection();
AccessDAO adao=new AccessDAO();

iRet=adao.getCount(connection);

connection.close();

}catch(Exception xe)
{
System.out.println("get Count Error:"+xe);
}
return iRet;
}

}

6.Re:谁解决过这样的问题? [Re: jameszhang] Copy to clipboard
Posted by: SimonLei
Posted on: 2003-03-06 14:30

把jdbcFactory 的 time out设长一点试试看

7.Re:谁解决过这样的问题? [Re: jameszhang] Copy to clipboard
Posted by: jameszhang
Posted on: 2003-03-06 16:37

把jdbcFactory 的 time out设长一点试试看
---------------------------------------------------------------
怎样设置?能详细说吗?谢谢!

8.Re:谁解决过这样的问题? [Re: jameszhang] Copy to clipboard
Posted by: SimonLei
Posted on: 2003-03-06 18:37

jameszhang wrote:
把jdbcFactory 的 time out设长一点试试看
---------------------------------------------------------------
怎样设置?能详细说吗?谢谢!


http://java.sun.com/products/jdbc/jdbc2_0_1-stdext-javadoc/javax/sql/DataSource.html

void   setLoginTimeout(int seconds)
Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.

9.Re:谁解决过这样的问题? [Re: jameszhang] Copy to clipboard
Posted by: jameszhang
Posted on: 2003-03-06 20:13

setLoginTimeout()我用了
放在
this.jdbcFactory = (javax.sql.DataSource)
c.lookup("myData");
之前
却直接抛出NULL异常
不知道放在那里比较合适?

10.Re:谁解决过这样的问题? [Re: jameszhang] Copy to clipboard
Posted by: SimonLei
Posted on: 2003-03-06 20:53

why not try it before you ask?

11.Re:谁解决过这样的问题? [Re: jameszhang] Copy to clipboard
Posted by: jameszhang
Posted on: 2003-03-06 21:10

我在下班前就试了!
setLoginTimeout()我
放在
this.jdbcFactory = (javax.sql.DataSource)
c.lookup("myData");
之前

调用他”直接“抛出NULL异常,没有重复调用

难道经常用WEBLOGIC 的高手没遇到过此类问题吗?
或是我的CODE写的不规范吗?

12.Re:谁解决过这样的问题? [Re: jameszhang] Copy to clipboard
Posted by: SimonLei
Posted on: 2003-03-06 21:51

If you put it before the

this.jdbcFactory = (javax.sql.DataSource)c.lookup("myData");

the jdbcFactory is null, of course it will throw exception.

why not put it after the line?

13.Re:谁解决过这样的问题? [Re: jameszhang] Copy to clipboard
Posted by: floater
Posted on: 2003-03-07 00:32

put your close statement in a final block.

If you open a connection, and something bombs out and so go directly to the catch block, you close() won't have a chance to be executed.

14.Re:谁解决过这样的问题? [Re: jameszhang] Copy to clipboard
Posted by: jameszhang
Posted on: 2003-03-07 09:01

哇!
我把他放在后面好使了!
在此感谢SimonLei!及各位高手!

setLoginTimeout()应该是jdbcFactory.getConnection()这个动作超时时间,我以为是this.jdbcFactory = (javax.sql.DataSource)c.lookup("myData")的,现在理解了,谢谢!

15.Re:谁解决过这样的问题? [Re: jameszhang] Copy to clipboard
Posted by: gunrose
Posted on: 2003-03-07 10:09

建议
失败的关闭和释放 JDBC 连接可能导致其它用户的连接经历长时间的等待。虽然超时的JDBC 连接会被 Server 退回而被回收 ,但必须等待这种情形发生。
使用完 JDBC 资源后关闭它们,还可以显式关闭 JDBC ResultSets等资源。如果没有显式关闭语句,则在完成了相关语句之后会释放 ResultsSets资源。

所以请确保您构建的代码在所有情况下,甚至在异常和错误条件下,都能关闭和释放 JDBC 资源。以下代码显示了 JDBC 资源的获得和使用都封装在Try-Catch-Finally结构中。其中,在 finally 子句中处理 JDBC 资源的关闭,使所有情况下关闭都将发生。
关闭 JDBC Connection 和 PreparedStatement 的正确方式
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
StringBuffer sqlBuffer=new StringBuffer();
//TODO
//...

try
{
  connection = getConnectionFromDataSource();
  statement = connection.prepareStatement(sqlBuffer.toString());
  resultSet = statement.executeQuery();
  //TODO
  //...

} catch (Throwable t)
{
  //TODO
  //...

} finally
{
  try
  {
    if (resultSet != null)
    {
      resultSet.close();
    }
    resultSet = null;

    if (statement != null)
    {
      statement.close();
    }
    statement = null;

    if (connection != null)
    {
      connection.close();
    }
    connection=null;
  } catch (Exception e)
  {
    //TODO
    //...

  }
}


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923