Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java EE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 谁解决过这样的问题?(快速多次调用后,WEBLOGIC 抛出 无可用JDBCRESOURCE 异常)
jameszhang



CJSDN高级会员


发贴: 1594
积分: 111
于 2003-03-06 10:52 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我做了SESSIONBEAN+ADO访问数据的例子,在一个客户快速多次调用后,WEBLOGIC 抛出 无可用JDBCRESOURC 异常,不知道要调整WEBLOGIC,还是要自己写程序限制??谢谢好手帮忙!

why edited on 2003-04-23 01:35

作者 Re:谁解决过这样的问题? [Re:jameszhang]
youlq



CJSDN高级会员


发贴: 260
积分: 95
于 2003-03-06 11:00 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
应该是调整Weblogic JDBC Pool size。


作者 Re:谁解决过这样的问题? [Re:jameszhang]
jameszhang



CJSDN高级会员


发贴: 1594
积分: 111
于 2003-03-06 11:59 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
调整WEBLOGIC JDBCSOURCE 后,情况好转,但还有极限,过极限就抛错


作者 Re:谁解决过这样的问题? [Re:jameszhang]
SimonLei



CJSDN高级会员


发贴: 288
积分: 100
于 2003-03-06 12:26 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
jameszhang wrote:
调整WEBLOGIC JDBCSOURCE 后,情况好转,但还有极限,过极限就抛错


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



You may say I am a dreamer, But I am not the only one.
My blog+wiki: http://blogsite.3322.org/
作者 Re:谁解决过这样的问题? [Re:jameszhang]
jameszhang



CJSDN高级会员


发贴: 1594
积分: 111
于 2003-03-06 14:04 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
那你看我这样关闭的是不是有错呢?另外如果我刷新的很慢,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;
}

}



作者 Re:谁解决过这样的问题? [Re:jameszhang]
SimonLei



CJSDN高级会员


发贴: 288
积分: 100
于 2003-03-06 14:30 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
把jdbcFactory 的 time out设长一点试试看


You may say I am a dreamer, But I am not the only one.
My blog+wiki: http://blogsite.3322.org/
作者 Re:谁解决过这样的问题? [Re:jameszhang]
jameszhang



CJSDN高级会员


发贴: 1594
积分: 111
于 2003-03-06 16:37 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
把jdbcFactory 的 time out设长一点试试看
---------------------------------------------------------------
怎样设置?能详细说吗?谢谢!



作者 Re:谁解决过这样的问题? [Re:jameszhang]
SimonLei



CJSDN高级会员


发贴: 288
积分: 100
于 2003-03-06 18:37 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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.



You may say I am a dreamer, But I am not the only one.
My blog+wiki: http://blogsite.3322.org/
作者 Re:谁解决过这样的问题? [Re:jameszhang]
jameszhang



CJSDN高级会员


发贴: 1594
积分: 111
于 2003-03-06 20:13 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
setLoginTimeout()我用了
放在
this.jdbcFactory = (javax.sql.DataSource)
c.lookup("myData");
之前
却直接抛出NULL异常
不知道放在那里比较合适?



作者 Re:谁解决过这样的问题? [Re:jameszhang]
SimonLei



CJSDN高级会员


发贴: 288
积分: 100
于 2003-03-06 20:53 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
why not try it before you ask?


You may say I am a dreamer, But I am not the only one.
My blog+wiki: http://blogsite.3322.org/
作者 Re:谁解决过这样的问题? [Re:jameszhang]
jameszhang



CJSDN高级会员


发贴: 1594
积分: 111
于 2003-03-06 21:10 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我在下班前就试了!
setLoginTimeout()我
放在
this.jdbcFactory = (javax.sql.DataSource)
c.lookup("myData");
之前

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

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


jameszhang edited on 2003-03-06 21:12

作者 Re:谁解决过这样的问题? [Re:jameszhang]
SimonLei



CJSDN高级会员


发贴: 288
积分: 100
于 2003-03-06 21:51 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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?



You may say I am a dreamer, But I am not the only one.
My blog+wiki: http://blogsite.3322.org/
作者 Re:谁解决过这样的问题? [Re:jameszhang]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2003-03-07 00:32 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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.



"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
- Martin Fowler, Refactoring - Improving the Design of Existing Code
作者 Re:谁解决过这样的问题? [Re:jameszhang]
jameszhang



CJSDN高级会员


发贴: 1594
积分: 111
于 2003-03-07 09:01 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
哇!
我把他放在后面好使了!
在此感谢SimonLei!及各位高手!

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



作者 Re:谁解决过这样的问题? [Re:jameszhang]
gunrose





发贴: 100
积分: 20
于 2003-03-07 10:09 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
建议
失败的关闭和释放 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
    //...

  }
}


gunrose edited on 2003-03-07 10:13


flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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