<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>聚沙成塔-小哈的记事薄 &#187; jdbc</title>
	<atom:link href="http://www.hashei.me/tag/jdbc/feed" rel="self" type="application/rss+xml" />
	<link>http://www.hashei.me</link>
	<description>一个系统工程师的絮叨</description>
	<lastBuildDate>Tue, 10 Jan 2012 18:03:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		
<!-- Start Of Script Generated By WP-PostViews Plus -->
<script type='text/javascript' src='http://hashei.me/wp-includes/js/jquery/jquery.js?ver=1.3.2'></script>
<script type="text/javascript">
/* <![CDATA[ */
jQuery.ajax({type:'GET',url:'http://hashei.me/wp-content/plugins/wp-postviews-plus/postviews_plus.php',data:'todowppvp=add&type=tag&id=22_1',cache:false,dataType:'script'});
/* ]]> */
</script>
<!-- End Of Script Generated By WP-PostViews Plus -->
	<item>
		<title>JDBC引发的服务器hang解决思路</title>
		<link>http://www.hashei.me/2009/08/jdbc_causes_server_hang.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=jdbc_causes_server_hang</link>
		<comments>http://www.hashei.me/2009/08/jdbc_causes_server_hang.html#comments</comments>
		<pubDate>Sun, 16 Aug 2009 03:58:36 +0000</pubDate>
		<dc:creator>hashei</dc:creator>
				<category><![CDATA[性能优化]]></category>
		<category><![CDATA[排错]]></category>
		<category><![CDATA[hang]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[weblogic]]></category>

		<guid isPermaLink="false">http://www.hashei.me/2009/08/jdbc_causes_server_hang.html</guid>
		<description><![CDATA[这篇也是转自BEA的官方文档，源地址在BEA被Oracle收购后就转到Oracle官网了，所以留为备份。虽然由BEA撰写，但是思路对所有中间件产品和应用开发都有用。]]></description>
			<content:encoded><![CDATA[<p>这篇也是转自BEA的官方文档，源地址在BEA被Oracle收购后就转到Oracle官网了，所以留为备份。</p>
<h4>JDBC Causes Server Hang</h4>
<p> <br />
<table style="width: 600px; text-align: left" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top"><font color="#009900"><b><u>Problem Description</u></b></font><br />A JDBC connection which is used by an application or by WebLogic Server itself will block one WebLogic Server execute thread for the complete duration of the calls that are made via this connection. The JVM will ensure that the CPU is given to runnable threads by its thread scheduling mechanism, while the thread that blocks on a SQL query needs to wait. However, the thread occupied by the JDBC call will be reserved and used for the application until the call returns from the SQL query.</p>
<p>Even a transaction timeout will not kill or timeout any action that is done by the resources that are enlisted in this transaction. The actions will run as long as they take, without interruption. A transaction timeout will set a flag on the transaction that will mark it as rollback only, so that any subsequent request to commit this transaction will fail with a <font size="-1">TimedOutException</font> or <font size="-1">RollbackException</font>. However, as mentioned above, the long running JDBC calls can lead to blocked WebLogic Server execute threads, which can finally lead to a hanging instance, if all threads are blocked and no execute thread remains available for handling incoming requests.</p>
<p>More recent WebLogic Server versions have a health check functionality that regularly checks if a thread does not react for a certain period of time (the default is 600 seconds). If this happens, an error message is printed to your log file similar to following:</td>
</tr>
</tbody>
</table>
<p> <br />
<table style="width: 600px" cellspacing="2" cellpadding="2" border="1">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204,204,204)"><font size="-1">####&lt;Nov 6, 2004 1:42:30 PM EST&gt; &lt;Warning&gt; &lt;WebLogicServer&gt; &lt;mydomain&gt; &lt;myserver&gt; &lt;CoreHealthMonitor&gt;<br /> &lt;kernel identity&gt; &lt;&gt; <br />&lt;000337&gt; &lt;ExecuteThread: &#8216;64&#8242; for queue: &#8216;default&#8217; has been busy for &#8220;740&#8243; seconds working on the request &#8220;Scheduled Trigger&#8221;, <br />which is more than the configured time (StuckThreadMaxTime) of &#8220;600&#8243; seconds.&gt;</font><font size="-1"><br /></font></td>
</tr>
</tbody>
</table>
<p> <br />
<table style="width: 600px; text-align: left" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top"><a name="1"></a>This does not interrupt the thread, as this is just a notification for the administrator. The only way a stuck thread becomes unstuck again is when the request it is handling finishes. In this case, you will find a message similar to following in your WebLogic Server&#8217;s log file:</td>
</tr>
</tbody>
</table>
<p> <br />
<table style="width: 600px" cellspacing="2" cellpadding="2" border="1">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204,204,204)"><font size="-1">####&lt;Nov 7, 2004 4:17:34 PM EST&gt; &lt;Info&gt; &lt;WebLogicServer&gt;&lt;mydomain&gt; &lt;myserver&gt; &lt;ExecuteThread: &#8216;66&#8242;<br /> for queue: &#8216;default&#8217;&gt;<br />&lt;kernel identity&gt; &lt;&gt; &lt;000339&gt; &lt;ExecuteThread: &#8216;66&#8242; for queue: &#8216;default&#8217; has become &#8220;unstuck&#8221;.&gt;</font><font size="-1"><br /></font></td>
</tr>
</tbody>
</table>
<p> <br />
<table style="width: 600px; text-align: left" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top">The time interval for the health check functionality is configurable. Please check <font size="-1">StuckThreadMaxTime</font> property in the <span style="font-style: italic">&lt;Server&gt;</span> tag of your <font size="-1">config.xml</font> file: <a href="http://e-docs.bea.com/wls/docs81/config_xml/Server.html#StuckThreadMaxTime">http://e-docs.bea.com/wls/docs81/config_xml/Server.html#StuckThreadMaxTime</a> or the &#8220;Detecting stuck threads&#8221; section in the WebLogic Server administration console help: <a href="http://e-docs.bea.com/wls/docs81/perform/WLSTuning.html#stuckthread">http://e-docs.bea.com/wls/docs81/perform/WLSTuning.html#stuckthread</a>.</p>
<p><font size="-1"><a href="#TOP">Top of Page</a></font></p>
<p><font color="#009900"><u><b><a name="Problem_Troubleshooting"></a>Problem Troubleshooting</b></u></font><br />Different programming techniques or JDBC connection pool configurations can lead to deadlocks or long running JDBC calls that lead to hanging WebLogic Server instances. General information about how to troubleshoot and analyze a hanging WebLogic Server instance is provided in <a href="http://support.bea.com/application_content/product_portlets/support_patterns/wls/Generic_Server_Hang_Pattern.html">Generic Server Hang Pattern</a>.</p>
<p>This pattern addresses JDBC calls causing a server hang and other well known JDBC-related causes for common problems leading to hanging WebLogic Server instance.&nbsp; Other Support Patterns referenced in this pattern are at the <a href="http://support.bea.com/application_content/product_portlets/support_patterns/wls/wls_support_patterns.jsp">WebLogic Server Support Patterns Site</a>.</p>
<p><span style="font-weight: bold; text-decoration: underline">Quick Links</span><font color="#009900"><u><b><br /></b></u></font>
<ul>
<li><a href="#Why_does_the_problem_occur"><span style="color: rgb(0,0,238); text-decoration: underline">Why does the problem occur?</span></a>
<li><a href="#Analysis_of_a_hanging_WebLogic_Server"><span style="color: rgb(0,0,238); text-decoration: underline">Analysis of a hanging WebLogic Server instance</span></a>
<li><a href="#Tips_and_Tricks_to_optimize_your_JDBC"><span style="color: rgb(0,0,238); text-decoration: underline">Tips and Tricks to optimize your JDBC code and JDBC connection pool configuration</span></a> </li>
</ul>
<p><a name="Why_does_the_problem_occur"></a><span style="font-weight: bold; text-decoration: underline">Why does the problem occur?</span><br />The following are some different possible reasons that can cause JDBC calls to lead to a hanging WebLogic Server instance:<br /> 
<ul>
<li>Use of <a href="#DriverManager.getConnection">DriverManager.getConnection()</a> in your JDBC code.
<li><a href="#Long_Running_SQL_Queries">SQL Queries</a> issued to the database take unexpectedly long time to return.
<li><a href="#Hanging_Database">Database</a> for which the JDBC connection pool is configured hangs and does not return from calls in a timely manner.
<li>A slow or overloaded <a href="#Slow_Network">network</a> causes database calls to slow down or hang.<br /> 
<li>A <a href="#Deadlock">deadlock</a> causes all execute threads to hang and wait forever.
<li><a href="#RefreshMinutes">RefreshMinutes or TestFrequencySeconds</a> property in the JDBC connection pool causes hang periods in WebLogic Server.
<li><a href="#Pool_Shrinking">JDBC connection pool shrinking</a> and re-creation of database connections causes long response times. </li>
</ul>
<p><font size="-1"><a href="#TOP">Top of Page</a></font></p>
<p><a name="DriverManager.getConnection"></a><span style="font-weight: bold">Synchronized DriverManager.getConnection()</span><br />Older JDBC application code sometimes uses <font size="-1">DriverManager.getConnection()</font> calls to retrieve a database connection using a certain driver. This technique is not recommended as it can cause deadlocks or at least relatively low performance for your connection requests. The reason behind this is, that all DriverManager calls are class-synchronized, meaning that one DriverManager call in one thread will block all other DriverManager calls in any other thread inside one WebLogic Server instance.</p>
<p>In addition to that, the constructor for a <font size="-1">SQLException</font> makes a DriverManager call, and most drivers have <font size="-1">DriverManager.println() </font>calls for logging, so any of these can block all other threads that issue a DriverManager call.</p>
<p><font size="-1">DriverManager.getConnection()</font> can take a relatively long time until it returns with the physical connection created to the database. Even if no deadlock occurs, all other calls need to wait until that one thread gets its connection. This is not a best practice in a multi-threaded system like WebLogic Server.</td>
</tr>
</tbody>
</table>
<p> <br />
<table style="width: 600px; text-align: left" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top">This information is taken from <a href="http://forums.bea.com/bea//thread.jspa?forumID=2022&amp;threadID=200063365&amp;messageID=202311284&amp;start=-1#202311284">http://forums.bea.com/bea//thread.jspa?forumID=2022&amp;threadID=200063365&amp;messageID=202311284&amp;start=-1#202311284</a>. </td>
</tr>
</tbody>
</table>
<table style="width: 600px; height: 252px; text-align: left" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top">Also our documentation clearly states that <font size="-1">DriverManager.getConnection()</font> should not be used: <a href="http://e-docs.bea.com/wls/docs81/faq/jdbc.html#501044">http://e-docs.bea.com/wls/docs81/faq/jdbc.html#501044</a>.</p>
<p><a name="2"></a>If you prefer to use JDBC connections in your JDBC code, you should use a WebLogic Server JDBC connection pool, define a DataSource for it, and get the connection from the DataSource. This will give you all advantages from a pool (resource sharing, connection reuse, connection refresh if a database was down, etc). It also will help you avoid the deadlocks that may happen with DriverManager calls. See detailed information on how to use JDBC connection pools, DataSources, and other JDBC objects in WebLogic Server at: <a href="http://e-docs.bea.com/wls/docs81/jdbc/intro.html#1036718">http://e-docs.bea.com/wls/docs81/jdbc/intro.html#1036718</a> and <a href="http://e-docs.bea.com/wls/docs81/jdbc/programming.html#1054307">http://e-docs.bea.com/wls/docs81/jdbc/programming.html#1054307</a>.</p>
<p>A typical thread blocked in a <font size="-1">DriverManager.getConnection()</font> call looks like:</td>
</tr>
</tbody>
</table>
<table style="width: 600px" cellspacing="2" cellpadding="2" width="611" border="1">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204,204,204)" width="605"><font size="-1">&#8220;ExecuteThread-39&#8243; daemon prio=5 tid=0&#215;401660 nid=0&#215;33 waiting for monitor entry [0xd247f000..0xd247fc68]<br />&nbsp; at java.sql.DriverManager.getConnection(DriverManager.java:188)<br />&nbsp; at com.bla.updateDataInDatabase(MyClass.java:296)<br />&nbsp; at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)<br />&nbsp; at weblogic.servlet.internal.ServletStubImpl.invokeServlet<br />(ServletStubImpl.java:120)<br />&nbsp; at weblogic.servlet.internal.ServletContextImpl.invokeServlet<br />(ServletContextImpl.java:945)<br />&nbsp; at weblogic.servlet.internal.ServletContextImpl.invokeServlet<br />(ServletContextImpl.java:909)<br />&nbsp; at weblogic.servlet.internal.ServletContextManager.invokeServlet<br />(ServletContextManager.java:269)<br />&nbsp; at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:392)<br />&nbsp; at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:274)<br />&nbsp; at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:130)</font></p>
</td>
</tr>
</tbody>
</table>
<p><font size="-1"><a href="#TOP">Top of Page</a></font></p>
<table style="width: 600px; text-align: left" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top"><a name="Long_Running_SQL_Queries"></a><span style="font-weight: bold">Long Running SQL Queries </span><br />Long running SQL queries block execute threads for their duration and until they return their result to the calling application. This means that a WebLogic Server instance needs to be configured to be able to handle enough calls simultaneously as they are requested by the application load. Limiting factors here are the number of execute threads and the number of connections in the JDBC connection pools. A general rule of thumb is to set the number of connections in the pool equally to the number of execute threads to enable optimal resource utilization. If JTS is used, some more connections in the pools should be available because connections may be reserved for transactions that are actually not active.</p>
<p>A thread hanging in a long running SQL call will show a very similar stack in a thread dump as the one for a <a href="#Hanging_Database">hanging database</a>. Please compare the next section for details.</p>
<p><a name="Hanging_Database"></a><span style="font-weight: bold">Hanging Database</span> <br />Good database performance is key for the performance of an application that relies on this database. Consequently, a hanging database can block many or all available execute threads in a WebLogic Server instance and finally lead to a hanging server. To diagnose this, you should take 5 to 10 thread dumps from your hanging WebLogic Server instance and check your execute threads (in the default queue or your application thread queue) to see if they are currently in SQL calls and waiting for a result from the database. A typical stack trace for a thread that currently issues a sql query could look similar to following example:</td>
</tr>
</tbody>
</table>
<p> <br />
<table style="width: 600px" cellspacing="2" cellpadding="2" border="1">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204,204,204)" width="719"><font size="-1">&#8220;ExecuteThread: &#8216;4&#8242; for queue: &#8216;weblogic.kernel.Default&#8217;&#8221; daemon prio=5 tid=0&#215;8e93c8 nid=0&#215;19 runnable [e137f000..e13819bc]<br />&nbsp; at java.net.SocketInputStream.socketRead0(Native Method)<br />&nbsp; at java.net.SocketInputStream.read(SocketInputStream.java:129)<br />&nbsp; at oracle.net.ns.Packet.receive(Unknown Source)<br />&nbsp; at oracle.net.ns.DataPacket.receive(Unknown Source)<br />&nbsp; at oracle.net.ns.NetInputStream.getNextPacket(Unknown Source)<br />&nbsp; at oracle.net.ns.NetInputStream.read(Unknown Source)<br />&nbsp; at oracle.net.ns.NetInputStream.read(Unknown Source)<br />&nbsp; at oracle.net.ns.NetInputStream.read(Unknown Source)<br />&nbsp; at oracle.jdbc.ttc7.MAREngine.unmarshalUB1(MAREngine.java:931)<br />&nbsp; at oracle.jdbc.ttc7.MAREngine.unmarshalSB1(MAREngine.java:893)<br />&nbsp; at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:375)<br />&nbsp; at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1983)<br />&nbsp; at oracle.jdbc.ttc7.TTC7Protocol.fetch(TTC7Protocol.java:1250)<br />&nbsp; &#8211; locked &lt;e8c68f00&gt; (a oracle.jdbc.ttc7.TTC7Protocol)<br />&nbsp; at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2529)<br />&nbsp; at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout<br />(OracleStatement.java:2857)<br />&nbsp; at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:608)<br />&nbsp; &#8211; locked &lt;e5cc44d0&gt; (a oracle.jdbc.driver.OraclePreparedStatement)<br />&nbsp; &#8211; locked &lt;e8c544c8&gt; (a oracle.jdbc.driver.OracleConnection)<br />&nbsp; at oracle.jdbc.driver.OraclePreparedStatement.executeQuery<br />(OraclePreparedStatement.java:536)<br />&nbsp; &#8211; locked &lt;e5cc44d0&gt; (a oracle.jdbc.driver.OraclePreparedStatement)<br />&nbsp; &#8211; locked &lt;e8c544c8&gt; (a oracle.jdbc.driver.OracleConnection)<br />&nbsp; at weblogic.jdbc.wrapper.PreparedStatement.executeQuery(PreparedStatement.java:80)<br />&nbsp; at myPackage.query.getAnalysis(MyClass.java:94)<br />&nbsp; at jsp_servlet._jsp._jspService(__jspService.java:242)<br />&nbsp; at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)<br />&nbsp; at weblogic.servlet.internal.ServletStubImpl$<br />ServletInvocationAction.run(ServletStubImpl.java:971)<br />&nbsp; at weblogic.servlet.internal.ServletStubImpl.invokeServlet<br />(ServletStubImpl.java:402)<br />&nbsp; at weblogic.servlet.internal.ServletStubImpl.invokeServlet<br />(ServletStubImpl.java:305)<br />&nbsp; at weblogic.servlet.internal.RequestDispatcherImpl.include<br />(RequestDispatcherImpl.java:607)<br />&nbsp; at weblogic.servlet.internal.RequestDispatcherImpl.include<br />(RequestDispatcherImpl.java:400)<br />&nbsp; at weblogic.servlet.jsp.PageContextImpl.include(PageContextImpl.java:154)<br />&nbsp; at jsp_servlet._jsp.__mf1924jq._jspService(__mf1924jq.java:563)<br />&nbsp; at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)<br />&nbsp; at weblogic.servlet.internal.ServletStubImpl$<br />ServletInvocationAction.run(ServletStubImpl.java:971)<br />&nbsp; at weblogic.servlet.internal.ServletStubImpl.invokeServlet<br />(ServletStubImpl.java:402)<br />&nbsp; at weblogic.servlet.internal.ServletStubImpl.invokeServlet<br />(ServletStubImpl.java:305)<br />&nbsp; at weblogic.servlet.internal.WebAppServletContext$<br />ServletInvocationAction.run(WebAppServletContext.java:6350)<br />&nbsp; at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)<br />&nbsp; at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)<br />&nbsp; at weblogic.servlet.internal.WebAppServletContext.invokeServlet<br />(WebAppServletContext.java:3635)<br />&nbsp; at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)<br />&nbsp; at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)<br />&nbsp; at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)</font></td>
</tr>
</tbody>
</table>
<p> <br />
<table style="width: 600px; text-align: left" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top">The thread will be in running state. You should compare the threads in your different thread dumps in order to see if they receive the return from the SQL call in a timely manner or if they hang in this same call for a longer period of time. If the thread dumps seem to imply long response times from SQL calls, the corresponding database logs should be checked to see if problems in the database cause this slow performance or hang situation.</p>
<p><font size="-1"><a href="#TOP">Top of Page</a></font></p>
<p><a name="Slow_Network"></a><span style="font-weight: bold">Slow Network</span> <br />Communication between WebLogic Server and the database relies on a well-performing and reliable network in order to serve the requests in a timely manner. Slow network performance can therefore lead to hanging or blocking execute threads waiting for results of SQL queries. The related stack traces will look similar to example above in <a href="#Hanging_Database">Hanging Database</a> section. It is not possible to find the root cause of the hanging or slow SQL queries by solely analyzing the WebLogic Server thread dumps. These give the first hint that something is wrong with the performance of the SQL calls. The next step is to check if there is a database or network problem that causes poorly performing SQL calls.</p>
<p><a name="Deadlock"></a><span style="font-weight: bold">Deadlock</span> <br />Both an application level deadlock as well as a deadlock on the database level can lead to hanging threads. You should check your thread dumps to see if there is an application level deadlock. Information on how to do this is provided in <a href="http://support.bea.com/application_content/product_portlets/support_patterns/wls/ServerHang_Application_Deadlock_Pattern.html">Server Hang &#8211; Application Deadlock Pattern</a>. A database deadlock can be detected either in the database log or by the SQL Exception that can be found in the WebLogic Server log file. An example for a related SQL Exception is:</td>
</tr>
</tbody>
</table>
<p> <br />
<table style="width: 600px" cellspacing="2" cellpadding="2" border="1">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204,204,204)"><font size="-1">java.sql.SQLException: ORA-00060: deadlock detected while waiting for resource<br />&nbsp; at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:170)<br />&nbsp; at oracle.jdbc.oci8.OCIDBAccess.check_error(OCIDBAccess.java:1614)<br />&nbsp; at oracle.jdbc.oci8.OCIDBAccess.executeFetch(OCIDBAccess.java:1225)<br />&nbsp; at oracle.jdbc.oci8.OCIDBAccess.parseExecuteFetch(OCIDBAccess.java:1338)<br />&nbsp; at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:1722)<br />&nbsp; at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1647)<br />&nbsp; at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2167)<br />&nbsp; at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate<br />(OraclePreparedStatement.java:404)</font><font size="-1"><br /></font></td>
</tr>
</tbody>
</table>
<p> <br />
<table style="width: 600px; text-align: left" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top">As it generally can take some time until a database detects a deadlock and resolves it by rolling back one or more transactions that cause the deadlock, one or more execute threads will be blocked until the rollback has finished.</p>
<p><a name="RefreshMinutes"></a><span style="font-weight: bold">RefreshMinutes or TestFrequencySeconds</span><br />If you see recurring periods of low database performance, slow SQL calls, or connection peaks, the setting of the <font size="-1">RefreshMinutes</font> or <font size="-1">TestFrequencySeconds</font><span style="font-style: italic"> </span>configuration property in your JDBC connection pools could be the reason. This is described in detail in <a href="http://support.bea.com/application_content/product_portlets/support_patterns/wls/Investigating_JDBC_Problems_Pattern.html">Investigating JDBC Problems Pattern</a>. Unless you do not have a firewall between your WebLogic Server instance and your database, you should disable this functionality.</p>
<p><a name="Pool_Shrinking"></a><span style="font-weight: bold">Pool Shrinking</span> <br />Physical connections to a database are resources that should be opened once and kept open as long as possible, as a new connection request is a considerable resource overhead for the database, the operating system kernel, and the WebLogic Server. Consequently, pool shrinking should be disabled on production systems in order to keep this overhead at a minimum. If pool shrinking is enabled, idle pool connections will be closed and reopened once connection requests to the pool cannot be satisfied.</p>
<p>As these activities can take some time, the related application requests may take an unexpectedly long time which can lead users to assume that the system hangs. Information on how to optimize JDBC connection pool configurations is provided in <a href="http://support.bea.com/application_content/product_portlets/support_patterns/wls/Investigating_JDBC_Problems_Pattern.html">Investigating JDBC Problems Pattern</a>.</p>
<p><font size="-1"><a href="#TOP">Top of Page</a></font></p>
<p><span style="font-weight: bold; color: rgb(0,0,0); text-decoration: underline"><a name="Analysis_of_a_hanging_WebLogic_Server"></a>Analysis of a hanging WebLogic Server instance</span><br />General information on how to analyze a hanging WebLogic Server instance is provided in <a href="http://support.bea.com/application_content/product_portlets/support_patterns/wls/Generic_Server_Hang_Pattern.html">Generic Server Hang Pattern</a>. </p>
<p>Most times it will be helpful to start with taking thread dumps from the hanging system in order to find out what is going on, e.g., what the different threads are doing and why they hang. Generally, thread dumps can be taken on production systems, however caution is necessary for very old versions of the JVM (&lt;1.3.1_09), as they may crash during thread dumps. Also if the WebLogic Server instance has a huge number of threads, it will mean that the thread dump will take awhile to complete, while the rest of the threads are blocked.</p>
<p>Please take more than one thread dump (5 to 10) with a delay of some seconds in between. This gives you the possibility to check the progress of the different threads. Also it will show if the system actually hangs (no progress at all) or if the throughput is extremely slow, which can seem to be a hanging system.</p>
<p>Information on how to take thread dumps is provided in &#8220;Generic Server Hang&#8221; support pattern or in our documentation: <a href="http://e-docs.bea.com/wls/docs81/cluster/trouble.html">http://e-docs.bea.com/wls/docs81/cluster/trouble.html</a>.</p>
<p>Also please check if the complete WebLogic Server instance hangs or if it is the application that hangs. &#8220;Generic Server Hang&#8221; support pattern also includes this information.</p>
<p><a name="3"></a>Analyzing the thread dumps can show if one of the reasons mentioned in the previous section <a href="#Why_does_the_problem_occur">Why does the problem occur?</a> actually is responsible for your hanging instance. If for example all your threads are in a DriverManager method like <font size="-1">getConnection()</font> then you have identified the root cause and need to change your application to use a DataSource or <font size="-1">Driver.connect()</font> instead of <font size="-1">DriverManager.getConnection()</font>.</p>
<p>A very useful tool, Samurai, can be used to analyze thread dumps and to monitor the progress of threads between different thread dumps. This can be downloaded from dev2dev at:&nbsp; <a href="http://dev2dev.bea.com/resourcelibrary/utilitiestools/adminmgmt.jsp">http://dev2dev.bea.com/resourcelibrary/utilitiestools/adminmgmt.jsp</a>.</p>
<p>A whitepaper on analyzing thread dumps on dev2dev: <a href="http://dev2dev.bea.com/products/wlplatform81/articles/thread_dumps.jsp">http://dev2dev.bea.com/products/wlplatform81/articles/thread_dumps.jsp</a> will also be helpful in going deeper into the thread dumps to find out more about the server hang. </p>
<p><font size="-1"><a href="#TOP">Top of Page</a></font></p>
<p><span style="font-weight: bold; color: rgb(0,0,0); text-decoration: underline"><a name="Tips_and_Tricks_to_optimize_your_JDBC"></a>Tips and Tricks to optimize your JDBC code and JDBC connection pool configuration</span><br />There are some best practices both in the development of JDBC code and also in the configuration practice of JDBC connection pools that can help to avoid common problems and optimize resource usage so that hanging server instances should not happen.</p>
<p><span style="font-weight: bold"><a name="JDBC_Programming"></a>JDBC Programming </span><br />In order to optimize resource usage in WebLogic Server and conserve database resources, you should use JDBC connection pools for your application&#8217;s JDBC calls. Connections created and destroyed in your application code generate an unnecessary overhead which should be avoided. For generic documentation on JDBC programming, see: <a href="http://e-docs.bea.com/wls/docs81/jdbc/rmidriver.html#1028977">http://e-docs.bea.com/wls/docs81/jdbc/rmidriver.html#1028977</a>. Also details on JDBC performance tuning are at: <a href="http://e-docs.bea.com/wls/docs81/jdbc/performance.html#1027791">http://e-docs.bea.com/wls/docs81/jdbc/performance.html#1027791</a>.</p>
<p>You can view comprehensive information on JDBC that will help to optimize your JDBC code and the utilization of your JDBC resources on dev2dev Java Database Connectivity page at: <a href="http://dev2dev.bea.com/technologies/jdbc/index.jsp">http://dev2dev.bea.com/technologies/jdbc/index.jsp</a>.</p>
<p><span style="font-weight: bold"><a name="JDBC_Connection_Pool_Configuration"></a>JDBC Connection Pool Configuration</span><br />The <a href="http://support.bea.com/application_content/product_portlets/support_patterns/wls/Investigating_JDBC_Problems_Pattern.html">Investigating JDBC Problems Pattern</a> has recommendations on how to configure a connection pool for production environments. In order to avoid hangs or bad performance, these configuration tips should be considered. </td>
</tr>
</tbody>
</table>
<p><font size="-1"><a href="#TOP">Top of Page</a></font></p>
<table style="width: 600px; text-align: left" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top"><font color="#009900"><u><b><a name="Known_Issues"></a>Known Issues</b></u></font><br /><span style="color: rgb(0,0,0)">You can periodically review the Release Notes for your version of WLS for more information on Known Issues or Resolved Issues in Service Packs and browse for JDBC server hang-related issues.&nbsp; </span><span style="color: rgb(0,0,0)">For your convenience, see the following: <br /></span>
<ul>
<li><span style="color: rgb(0,0,0)"><a href="http://edocs/wls/docs81/notes/index.html">WLS 8.1 Release Notes</a></span>
<li><span style="color: rgb(0,0,0)"><a href="http://edocs/wls/docs70/notes/index.html">WLS 7.0 Release Notes</a></span>
<li><span style="color: rgb(0,0,0)"><a href="http://edocs/wls/docs61/notes/index.html">WLS 6.1 Release Notes</a></span> </li>
</ul>
<p><span style="color: rgb(0,0,0)">Please note that changes have been made in <a href="http://e-docs.bea.com/wls/docs81/notes/resolved_sp03.html#1817208">WLS 8.1 SP3</a> to resolve CR134921, where for certain JDBC connections, the call to roll back a transaction was not being handled immediately because the driver had to wait for any currently-executing statement to return.&nbsp; <br /><span style="color: rgb(0,0,0)"><br />Searching will also return Release Notes, as well as other Support Solutions and CR-related information as noted at <a href="#Need_Further_Help?">Need Further Help?</a>.&nbsp; Contract customers who are logged in at </span><span style="font-size: 12pt; font-family: 'Times New Roman'"><a href="http://support.bea.com/">http://support.bea.com/</a> will also see a Browse portlet for both Solutions and Bug Central where latest available CRs can be browsed by Product version.</span><br /></span></td>
</tr>
</tbody>
</table>
<p> <br />
<table style="width: 600px; color: rgb(0,0,0); text-align: left" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top"><span style="text-decoration: underline"><span style="font-weight: bold"><a name="Need_Further_Help?"></a>Need Further Help?</span></span><br /><span style="font-size: 12pt; font-family: 'Times New Roman'">If you have followed the pattern, but still require additional help, you can:<br /></span>
<ol>
<li><span style="font-size: 12pt; font-family: 'Times New Roman'">Query AskBEA at </span><span style="font-size: 12pt; font-family: 'Times New Roman'"><a href="http://support.bea.com/">http://support.bea.com/</a></span><span style="font-size: 12pt; font-family: 'Times New Roman'"> </span><span style="font-size: 12pt; font-family: 'Times New Roman'">using </span><span style="font-size: 12pt; font-family: 'Times New Roman'">&#8220;jdbc server hang&#8221;, as an example, to discover other published solutions.&nbsp; </span><span style="font-size: 12pt; color: rgb(0,0,0); font-family: 'Times New Roman'">Contract Support Customers: Ensure you are logged to access available CR-related information.</span>
<li><span style="font-size: 12pt; font-family: 'Times New Roman'">Ask a more detailed question on one of BEA&#8217;s newsgroups at </span><a href="http://newsgroups.bea.com/">http://forums.bea.com<br /></a></li>
</ol>
<p>If this does not resolve your issue and you have a valid Support Contract, you can open a Support Case by logging in at: <span style="font-size: 12pt; font-family: 'Times New Roman'"><a href="http://support.bea.com/">http://support.bea.com/</a></span> .</td>
</tr>
</tbody>
</table>
<p> <br />
<table width="600" border="2">
<tbody>
<tr>
<td>
<p><strong>FEEDBACK</strong></p>
<p><font color="#000000">Please provide us input on whether or not this Support Diagnostic Pattern <strong>&#8220;JDBC Causes Server Hang&#8221;</strong> helped, any clarifications you needed, and any requests for new topics to <a href="mailto:support.ke@bea.com?subject=Patterns%20Feedback:%20JDBC%20Causes%20Server%20Hang&amp;body=">Support Diagnostic Patterns</a>. <br /></font></p>
</td>
</tr>
</tbody>
</table>
<p> <br />
<table width="600" border="2"><!--DWLayoutTable--><br />
<tbody>
<tr>
<td height="78">
<p><strong>DISCLAIMER NOTICE:</strong></p>
<p>BEA Systems, Inc. provides the technical tips and patches on this Website for your use under the terms of BEA&#8217;s maintenance and support agreement with you. While you may use this information and code in connection with software you have licensed from BEA, BEA makes no warranty of any kind, express or implied, regarding the technical tips and patches.</p>
<p>Any trademarks referenced in this document are the property of their respective owners. Consult your product manuals for complete trademark information.</p>
</td>
</tr>
</tbody>
</table>
<hr /><small>  Copyright &copy; 2008 This feed is for personal, non-commercial use only<br />
<a href=www.hashei.com >聚沙成塔-小哈的记事薄</a> by hashei 
如果喜欢，欢迎订阅<a href=feed.hashei.com >feed.hashei.com</a><br />
Digital Fingerprint:
 10f920a9f2bae51c3c73c4f5fb50a949</small>]]></content:encoded>
			<wfw:commentRss>http://www.hashei.me/2009/08/jdbc_causes_server_hang.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Websphere入门篇（三）-建立连接池</title>
		<link>http://www.hashei.me/2009/04/connect-to-database.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=connect-to-database</link>
		<comments>http://www.hashei.me/2009/04/connect-to-database.html#comments</comments>
		<pubDate>Tue, 28 Apr 2009 14:12:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Websphere系列]]></category>
		<category><![CDATA[初级入门]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[was]]></category>

		<guid isPermaLink="false">http://www.hashei.me/?p=229</guid>
		<description><![CDATA[1        WebSphere配置
1.1      通过 http://hostname:9060/admin进入Websphere 管理控制台，并用管理员用户登录
1.2      设置Oracle驱动环境变量（针对Oracle数据库）
1.2.1   将oracle的java驱动ojdbc14.jar复制到&#8230;/WebSphere/AppServer/lib/ext目录中。
1.2.2   修改数据库驱动环境变量
Ø        进入&#8221;环境àWebSphere变量&#8221;
Ø        修改ORACLE JDBC DRIVER PATH，值为1.2.1节中ojdbc14.jar 所在的目录，使用绝对路径。
Ø        确定并保存
1.3      新建J2C认证数据
Ø        进入&#8221;安全性——安全管理、应用程序和基础结构—— Java 认证和授权服务（JAAS）——J2C认证数据&#8221;
Ø        新建一个认证数据条目
Ø        别名为：取一个容易记住的，假设为bm1
Ø        用户标识为：  数据库连接用户
Ø        密码为：  数据库连接密码
1.4      新建JDBC提供者
Ø        进入&#8221;资源——JDBC——JDBC提供程序&#8221;
Ø        选择合适的作用域，一般选择server1
Ø        新建JDBC提供程序
Ø        数据库类型为：oracle
Ø        提供者类型为：Oracle JDBC Driver
Ø        实施类型为：连接池数据源
Ø        名称为：oracle92
Ø        点击下一步
Ø        类路径为：${ORACLE JDBC DRIVER PATH}/ojdbc14.jar
Ø        下一步
Ø        完成并保存
1.5      新建数据源
Ø        进入&#8221;资源——JDBC——数据源&#8221;
Ø        选择合适的作用域，一般选择server1（根据你要发布的Server来）
Ø        新建数据源
Ø        名称为：随便起
Ø        JNDI名称为：jdbc/需要使用的jndi name
Ø        组件管理的认证别名为：hostnameNode01/ bm1（还记得之前建立的J2C别名么）
Ø        下一步
Ø        选择刚才建立的JDBC提供程序，
Ø        设置URL：jdbc:oracle:thin:@ip:1521:sid
Ø        下一步
Ø        [...]]]></description>
			<content:encoded><![CDATA[<p><strong>1        </strong><strong>WebSphere</strong><strong>配置</strong></p>
<p>1.1      通过 http://hostname:9060/admin进入Websphere 管理控制台，并用管理员用户登录</p>
<p>1.2      设置Oracle驱动环境变量（针对Oracle数据库）</p>
<p>1.2.1   将oracle的java驱动ojdbc14.jar复制到&#8230;/WebSphere/AppServer/lib/ext目录中。</p>
<p>1.2.2   修改数据库驱动环境变量</p>
<p>Ø        进入&#8221;环境àWebSphere变量&#8221;</p>
<p>Ø        修改ORACLE JDBC DRIVER PATH，值为1.2.1节中ojdbc14.jar 所在的目录，使用绝对路径。</p>
<p>Ø        确定并保存</p>
<p>1.3      新建J2C认证数据</p>
<p>Ø        进入&#8221;安全性——安全管理、应用程序和基础结构—— Java 认证和授权服务（JAAS）——J2C认证数据&#8221;</p>
<p>Ø        新建一个认证数据条目</p>
<p>Ø        别名为：取一个容易记住的，假设为bm1</p>
<p>Ø        用户标识为：  数据库连接用户</p>
<p>Ø        密码为：  数据库连接密码</p>
<p>1.4      新建JDBC提供者</p>
<p>Ø        进入&#8221;资源——JDBC——JDBC提供程序&#8221;</p>
<p>Ø        选择合适的作用域，一般选择server1</p>
<p>Ø        新建JDBC提供程序</p>
<p>Ø        数据库类型为：oracle</p>
<p>Ø        提供者类型为：Oracle JDBC Driver</p>
<p>Ø        实施类型为：连接池数据源</p>
<p>Ø        名称为：oracle92</p>
<p>Ø        点击下一步</p>
<p>Ø        类路径为：${ORACLE JDBC DRIVER PATH}/ojdbc14.jar</p>
<p>Ø        下一步</p>
<p>Ø        完成并保存</p>
<p>1.5      新建数据源</p>
<p>Ø        进入&#8221;资源——JDBC——数据源&#8221;</p>
<p>Ø        选择合适的作用域，一般选择server1（根据你要发布的Server来）</p>
<p>Ø        新建数据源</p>
<p>Ø        名称为：随便起</p>
<p>Ø        JNDI名称为：jdbc/需要使用的jndi name</p>
<p>Ø        组件管理的认证别名为：hostnameNode01/ bm1（还记得之前建立的J2C别名么）</p>
<p>Ø        下一步</p>
<p>Ø        选择刚才建立的JDBC提供程序，</p>
<p>Ø        设置URL：jdbc:oracle:thin:@ip:1521:sid</p>
<p>Ø        下一步</p>
<p>Ø        确定并保存</p>
<p>Ø        选择刚刚建立的数据源，测试连接，看看是否正常</p>
<hr /><h2>Related posts:</h2><ul><li><a href="http://www.hashei.me/2009/08/jdbc_causes_server_hang.html" rel="bookmark" title="Permanent Link: JDBC引发的服务器hang解决思路">JDBC引发的服务器hang解决思路</a></li><li><a href="http://www.hashei.me/2010/05/enable-lagepages-for-jvm.html" rel="bookmark" title="Permanent Link: 为JVM启用大页面支持">为JVM启用大页面支持</a></li><li><a href="http://www.hashei.me/2010/02/oracle-04020_and_oracle-00942_problems.html" rel="bookmark" title="Permanent Link: 充当了一回DBA">充当了一回DBA</a></li><li><a href="http://www.hashei.me/2009/09/weblogic-cluster-step-by-step.html" rel="bookmark" title="Permanent Link: WebLogic9和10集群安装配置过程">WebLogic9和10集群安装配置过程</a></li><li><a href="http://www.hashei.me/2009/10/db2_cluster_with_microsoft_mscs.html" rel="bookmark" title="Permanent Link: 在Windows 上利用 MSCS 创建高可用性的 DB2 集群服务">在Windows 上利用 MSCS 创建高可用性的 DB2 集群服务</a></li></ul><hr /><small>  Copyright &copy; 2008 This feed is for personal, non-commercial use only<br />
<a href=www.hashei.com >聚沙成塔-小哈的记事薄</a> by hashei 
如果喜欢，欢迎订阅<a href=feed.hashei.com >feed.hashei.com</a><br />
Digital Fingerprint:
 10f920a9f2bae51c3c73c4f5fb50a949</small>]]></content:encoded>
			<wfw:commentRss>http://www.hashei.me/2009/04/connect-to-database.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

