<?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; hang</title>
	<atom:link href="http://www.hashei.me/tag/hang/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=147_1',cache:false,dataType:'script'});
/* ]]> */
</script>
<!-- End Of Script Generated By WP-PostViews Plus -->
	<item>
		<title>应用程序死锁导致服务器挂起的介绍</title>
		<link>http://www.hashei.me/2009/08/serverhang_application_deadlock.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=serverhang_application_deadlock</link>
		<comments>http://www.hashei.me/2009/08/serverhang_application_deadlock.html#comments</comments>
		<pubDate>Mon, 17 Aug 2009 08:09:00 +0000</pubDate>
		<dc:creator>hashei</dc:creator>
				<category><![CDATA[weblogic]]></category>
		<category><![CDATA[排错]]></category>
		<category><![CDATA[deadlock]]></category>
		<category><![CDATA[hang]]></category>

		<guid isPermaLink="false">http://www.hashei.me/2009/08/serverhang_application_deadlock.html</guid>
		<description><![CDATA[原来好东西都躲到Metalink上去了
Problem Description
An inadvertent deadlock in the application code can cause a server to hang. For example, a situation in which thread1 is waiting for resource1 and is holding a lock on resource2, while thread2 needs resource2 and is holding the lock on resource1. Neither thread can progress.
Problem Troubleshooting
This Application Deadlock pattern should be used only [...]]]></description>
			<content:encoded><![CDATA[<h3>原来好东西都躲到Metalink上去了</h3>
<h3>Problem Description</h3>
<p>An inadvertent deadlock in the application code can cause a server to hang. For example, a situation in which thread1 is waiting for resource1 and is holding a lock on resource2, while thread2 needs resource2 and is holding the lock on resource1. Neither thread can progress.</p>
<h3>Problem Troubleshooting</h3>
<p>This Application Deadlock pattern should be used only after doing all the steps in the <b><a href="http://support.bea.com/application_content/product_portlets/support_patterns/wls/GenericServerHangPattern.html">Generic Server Hang</a></b> pattern. One indicator that this is an application deadlock problem is that thread dumps will show the threads are in the application methods. Several thread dumps taken a few seconds apart will show that the threads are not progressing. Troubleshooting this problem will involve reviewing the application code. There exists a thread analyzer tool at BEA <a href="http://dev2dev.bea.com/products/wlplatform81/articles/thread_dumps.jsp">dev2dev</a> which has proven useful in analysis of the thread dumps.</p>
<h4>Quick Links</h4>
<ul>
<li><a href="http://www.hashei.me/TEMP/non15BB.htm#Why_does_the_problem_occur">Why does the problem occur?</a></li>
<li><a href="http://www.hashei.me/TEMP/non15BB.htm#Known_WebLogic_Server_Issues">Known WebLogic Server Issues</a></li>
<li><a href="http://www.hashei.me/TEMP/non15BB.htm#External_Resources">External Resources</a></li>
</ul>
<p> <span id="more-698"></span><br />
<h3><a name="Why_does_the_problem_occur"></a>Why does the problem occur?</h3>
<p>Fundamentaly, this problem happens because the design and implementation of the application has introduced the possibility of deadlocks. These types of problems may only show up under heavy load. Therefore, these applications often pass through QA testing and become problems in production.</p>
<p>Coding problems to look for:</p>
<ul>
<li>Unnecessary use of synchronized java classes, e.g., using <code>Hashtable</code> (synchronized) versus the use of <code>HashMap</code>(unsynchronized) </li>
<li>Application has a synchronized method that contains synchronized object method calls. See example below.
<p>import java.util.Vector;&#160;&#160; &lt;&#8211; Vector is a synchronized java class       <br />Public class Employee {        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Vector names = new Vector();        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Employees () {        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Object object = new Object();        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; synchronized (object) {        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; names.add(&quot;al&quot;);        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; names.add(&quot;Saganich&quot;);        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; synchronized String getName (int index) {        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; String name = (String) names.elementAt(index);        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return name;        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
</li>
<li>Using synchronization around long running complex code. </li>
<li>Threads are waiting on resources that will never become available.</li>
</ul>
<h4>Application Design</h4>
<ul>
<li>The application uses up all of the configured number of threads. This can happen when an executing thread reaches a point where it must wait for work done by another thread to complete. The timing may be that the waited for method which this thread is trying to enter is long running. Eventually, all the threads must reach this long running method. After running awhile, the application will find that the threads will be lined up waiting for this long running method. No new work can be introduced because the allocated number of threads is all used up. See example below.
<p>import java&#8230;..;       <br />import java&#8230;..;        <br />public class myAppMethods {        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; public String getName(String name) {        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; String lastname =&#160; getLastName(name);        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return lastname;        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; public synchronized String getLastName (String name) {        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; do a DB Lookup&#160;&#160;&#160; &lt;&#8212;&#8212;&#8212;&#8212; takes mucho time to get a last name        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return lastname;        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>If the database if very slow, the server can appear to be hung because the threads will line up trying to get access to the database and all the available threads could eventually be used up.</p>
</li>
<li>The application running inside a WebLogic Server invokes a service on another WebLogic instance on a remote machine. The remote service invoked on the remote machine makes a call back to the first server. This sets up the opportunity for a deadlock on the first server especially under heavy load. The first server has an execution thread that is tied up waiting for an inbound response. This inbound response will require a thread from the same execute pool as the thread that is waiting to receive the response.
<p>If the first server is faster than the remote server, eventually all the threads in the execute pool will be exhausted by the server making outbound requests with fewer threads available for processing inbound responses. As the load grows, the number of outgoing requests that cannot complete their work grows while they wait for an inbound response to complete. Below is an example of a thread in the <code>waitForDataResponseImpl.java</code> method of.</p>
<p>&quot;ExecuteThread: &#8216;52&#8242; for queue: &#8216;default&#8217;&quot; daemon prio=5 tid=0&#215;4b3e40b0 nid=0&#215;1170 waiting on monitor [0x4c74f000..0x4c74fdbc]&#160; <br />at java.lang.Object.wait(Native Method)        <br />at&#160; <br />weblogic.rjvm.ResponseImpl.waitForData(ResponseImpl.java:72)</p>
</li>
</ul>
<p><a href="http://www.hashei.me/TEMP/non15BB.htm#TOP">Top of Page</a></p>
<h3><a name="Known_WebLogic_Server_Issues"></a>Known WebLogic Server Issues</h3>
<p>WebLogic Server cannot detect deadlocked threads. Some JVM&#8217;s are able to do so. See <a href="http://www.hashei.me/TEMP/non15BB.htm#External_Resources">External Resources</a>. There is a tool available for thread analysis as well as good information about thread dumps on BEA <a href="http://dev2dev.bea.com/products/wlplatform81/articles/thread_dumps.jsp">dev2dev</a>.</p>
<p><a href="http://www.hashei.me/TEMP/non15BB.htm#TOP">Top of Page</a></p>
<h3><a name="External_Resources"></a>External Resources</h3>
<p>If you suspect a deadlock, it is helpful to go to the site of the JVM vendor to learn if there are clues provided for you in their thread dumps. If you are using JDK 1.3.1 you can add <code>- XX:+JavaMonitorInStack Trace</code> to show locking more explicitly/builtin. Here is an example of an HP JVM thread dump in which it is clearly marked that the threads&#8217; state are waiting on monitor, and the monitor is identified. See example below.</p>
<p>&quot;msg 0-941667944865&quot; (TID:0&#215;7b1a5ba0, sys_thread_t:0&#215;2a4290,   <br />&#160; state:<b>Waiting on Monitor</b>,    <br />&#160; thread_t: t@108, stack_base:0&#215;7a76e000, stack_size:0&#215;20000,    <br /> pc: 0xc01ea178, monitor = <b>0&#215;25334</b>) prio=8    <br />&#160; MsgThread.rest(Compiled Code)    <br />&#160; MsgThread.run(Compiled Code)    <br />&quot;msg 3-941667944865&quot; (TID:0&#215;7b1a5a80, sys_thread_t:0&#215;263278,    <br />&#160; state:<b>Waiting on Monitor</b>,    <br />&#160; thread_t: t@105, stack_base:0&#215;7a95d000, stack_size:0&#215;20000,    <br /> pc: 0xc01ea178, monitor = <b>0&#215;25334</b>) prio=8    <br />&#160; MsgThread.rest(Compiled Code)    <br />&#160; MsgThread.run(Compiled Code)    <br />&quot;msg 5-941667944864&quot; (TID:0&#215;7b1a5f08, sys_thread_t:0&#215;2c42d8,    <br />&#160; state:<b>Waiting on </b>Monitor,    <br />&#160; thread_t: t@106, stack_base:0&#215;7aa65000, stack_size:0&#215;20000,    <br /> pc: 0xc01ea178, monitor = <b>0&#215;25334</b>) prio=8    <br />&#160; MsgThread.rest(Compiled Code)    <br />&#160; MsgThread.run(Compiled Code)</p>
<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/serverhang_application_deadlock.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>应用服务器发生hang的诊断方法</title>
		<link>http://www.hashei.me/2009/08/java_generic_server_hang.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=java_generic_server_hang</link>
		<comments>http://www.hashei.me/2009/08/java_generic_server_hang.html#comments</comments>
		<pubDate>Sat, 15 Aug 2009 15:04:26 +0000</pubDate>
		<dc:creator>hashei</dc:creator>
				<category><![CDATA[性能优化]]></category>
		<category><![CDATA[排错]]></category>
		<category><![CDATA[hang]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[thread dump]]></category>
		<category><![CDATA[weblogic]]></category>

		<guid isPermaLink="false">http://www.hashei.me/2009/08/java_generic_server_hang.html</guid>
		<description><![CDATA[写在前面
其实这是BEA官网上的一篇文档，是在weblogic8.1的时候推出的。在BEA被Oracle收购后，所有的support文章也就被重定向到Oracle的官网首页= =，而且google的快照也没有了。这篇来自无意间google到的一个外国论坛，虽然是写在8.1时，但是解决问题的方法和思路现在依旧有效。本想理解之后结合案例来写一篇，但是最近一直没有遇到相关的问题，而且觉得那样也许会破坏文章的完整性，所以放出原文，既在网上留个副本，也能让大家各取所需，见仁见智。
从内容看，你会发现除了这篇，还有EJB_RMI Server Hang、Application Dead Lock、JDBC Causes Server Hang，但是那个论坛里还能找到的仅有JDBC Causes Server Hang一篇。所以如果你接触weblogic比较早，保存过另两篇文章，或者在网上看到了，那请留言说明，万分感谢。
Generic Hang



Problem Description
A server hang is suspected when:

The server does not respond to new requests.
Requests time out.
Requests take longer and longer to process (may be on the way to a hang).
A server crash is not usually a symptom of a hung server but may [...]]]></description>
			<content:encoded><![CDATA[<h4>写在前面</h4>
<p style="text-indent: 24pt">其实这是BEA官网上的一篇文档，是在weblogic8.1的时候推出的。在BEA被Oracle收购后，所有的support文章也就被重定向到Oracle的官网首页= =，而且google的快照也没有了。这篇来自无意间google到的一个外国论坛，虽然是写在8.1时，但是解决问题的方法和思路现在依旧有效。本想理解之后结合案例来写一篇，但是最近一直没有遇到相关的问题，而且觉得那样也许会破坏文章的完整性，所以放出原文，既在网上留个副本，也能让大家各取所需，见仁见智。</p>
<p style="text-indent: 24pt">从内容看，你会发现除了这篇，还有EJB_RMI Server Hang、Application Dead Lock、JDBC Causes Server Hang，但是那个论坛里还能找到的仅有JDBC Causes Server Hang一篇。所以如果你接触weblogic比较早，保存过另两篇文章，或者在网上看到了，那请留言说明，万分感谢。</p>
<h4><span style="font-size: medium;"><span style="line-height: normal; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Generic Hang</span></span></h4>
<table style="width: 600px; text-align: left;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top"><strong><span style="text-decoration: underline;">Problem Description</span></strong><br />
A server hang is suspected when:</p>
<ul>
<li>The server does not respond to new requests.</li>
<li>Requests time out.</li>
<li>Requests take longer and longer to process (may be on the way to a hang).</li>
<li>A server crash is not usually a symptom of a hung server but may follow.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<table style="width: 600px; text-align: left;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top"><span style="text-decoration: underline;"><strong>Problem Troubleshooting</strong><strong><br />
</strong></span>Please note that not all of the following items would need to be done. Some issues can be solved by only following a few of the items.<strong><span style="text-decoration: underline;">Quick Links:</span></strong></p>
<ul>
<li><span style="text-decoration: underline;"><a href="#Why_does_the_problem_occur?">Why does the problem occur?</a></span></li>
<li><span style="text-decoration: underline;"><a href="#Potential_Causes_of_Server_Hang">Potential Causes of Server Hang</a></span></li>
<li><span style="text-decoration: underline;"><a href="#Basic_Steps">Basic Steps</a></span></li>
<li><span style="text-decoration: underline;"><a href="#Known_WebLogic_Server_Issues">Known WebLogic Server Issues</a></span></li>
<li><span style="text-decoration: underline;"><a href="#Collecting_Thread_Dumps">Collecting Thread Dumps</a></span></li>
<li><span style="text-decoration: underline;"><a href="#Analysis_of_Thread_Dump">Analysis of a Thread Dump</a></span></li>
</ul>
<p><span style="text-decoration: underline;"><strong><a name="Why_does_the_problem_occur?"></a></strong><span style="text-decoration: underline;"><strong>Why does the problem occur?</strong></span><strong> </strong></span><br />
A server can hang for a variety of reasons (refer to <a href="#Potential_Causes_of_Server_Hang">Potential Causes of Server Hang</a>). Generally, a server hangs because of a lack of some resource. Lack of a resource prevents the server from servicing requests. For example, because of a problem (deadlock) or volume of requests there may be no execute threads available to do any work; all are busy or busy with previous requests.</p>
<p><span><a href="#TOP">Top of Page</a></span></p>
<p><strong><span style="text-decoration: underline;"><a name="Potential_Causes_of_Server_Hang"></a></span></strong></td>
</tr>
</tbody>
</table>
<table border="1" width="600">
<tbody>
<tr>
<td width="45%">
<div><strong>Topic</strong></div>
</td>
<td width="25%">
<div><strong>Pattern Name</strong></div>
</td>
<td width="30%">
<div><strong>Link</strong></div>
</td>
</tr>
<tr>
<td valign="top">RMI, RJVM responses – all threads tied up waiting for RJVM, RMI responses.</td>
<td>EJB_RMI Server Hang</td>
<td>
<div><a href="http://support.bea.com/application_content/product_portlets/support_patterns/wls/EJB_RMI_Server_Hang_Pattern.html">EJB_RMI Server Hang</a></div>
</td>
</tr>
<tr>
<td valign="top">Application Deadlock – thread locks resource1 then waits for lock for resource2. Another thread locks resource2 and then waits for lock for resource1.</td>
<td>Application Deadlock Causes Server Hang</td>
<td style="color: #ff0000">
<div><a href="http://support.bea.com/application_content/product_portlets/support_patterns/wls/ServerHang_Application_Deadlock_Pattern.html">Application Dead Lock</a></div>
</td>
</tr>
<tr>
<td valign="top">Threads are all used up, none available for new work.</td>
<td>Thread Usage Server Hang</td>
<td>TBD</td>
</tr>
<tr>
<td valign="top">Garbage Collection taking too much time.</td>
<td>Garbage Collection Server Hang</td>
<td>TBD</td>
</tr>
<tr>
<td valign="top">JSP improper settings for servlet times, e.g. PageCheckSeconds.</td>
<td>JSP cause Server Hang</td>
<td>TBD</td>
</tr>
<tr>
<td valign="top">Long Running JDBC calls or JDBC deadlocks lead to a hang.</td>
<td><span style="color: #000000">JDBC Causes Server Hang</span></td>
<td style="text-align: center"><a href="http://support.bea.com/application_content/product_portlets/support_patterns/wls/JDBC_Causes_Server_Hang_Pattern.html">JDBC Causes Server Hang</a></td>
</tr>
<tr>
<td valign="top">JVM hang during (code optimization), looks like server hang.</td>
<td>Server Hang in Code Optimization</td>
<td>TBD</td>
</tr>
<tr>
<td valign="top">JSP compilation causes server hang under heavy load.</td>
<td>JSP Compilation Server Hang</td>
<td><a href="http://support.bea.com/application_content/product_portlets/support_patterns/wls/JDBC_Causes_Server_Hang_Pattern.html"></a>TBD</td>
</tr>
<tr>
<td valign="top">SUN JVM bugs, e.g. Light weight thread library.</td>
<td>Sun JVM Bugs that Cause Server Hangs</td>
<td>TBD</td>
</tr>
</tbody>
</table>
<table style="width: 600px; text-align: left;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top"><span><a href="#TOP">Top of Page</a></span></p>
<p><a name="Basic_Steps"></a><br />
When a server is hanging, first ping the server using <span style="font-family: 'Courier New', Courier, mono;">java weblogic.Admin t3://server:port PING</span>. If the server can respond to the ping, it may be that the application is hanging and not the server itself.</p>
<p>Ensure that the server is actually hanging and not doing garbage collection. To verify, restart the server with <span style="font-family: 'Courier New', Courier, mono;">-verbosegc</span> turned on, and redirect <span style="font-family: 'Courier New', Courier, mono;">stdout</span> and <span style="font-family: 'Courier New', Courier, mono;">stderr</span> to one file. When the server stops responding, it can be determined if it’s doing garbage collection or it is really hanging.  If the garbage collection is taking too long (&gt;10 seconds), the server may miss the heartbeats that servers use to keep each other informed of the topoplogy of the cluster.</p>
<p>WebLogic Server uses the ‘default’ thread queue or a configured application specific thread queue<span style="color: #ff0000"> </span>to service client requests.<span style="color: #ff0000"> </span>Client requests will only be handled in the default queue if no application specific thread queue is defined.  Please see <a href="http://e-docs.bea.com/wls/docs81/perform/AppTuning.html#11052010">Tuning WebLogic Server Applications</a>, <a href="http://e-docs.bea.com/wls/docs81/perform/WLSTuning.html#1140013">Tuning the Default Execute Queue Threads</a>, and <a href="http://e-docs.bea.com/wls/docs81/perform/topten.html#1129089">Tuning WebLogic Server Performance Parameters</a> for more information on defining application specific thread queues. <a href="http://e-docs.bea.com/wls/docs81/perform/topten.html#1129089"><br />
</a></p>
<p>In release 8.1, a change was made to the thread architecture in WebLogic Server.  A specific kernel thread group for internal WebLogic tasks was created.  This was found to be necessary to avoid deadlocks that occurred in earlier releases when all threads in the &#8216;default&#8217; thread queue were used and none were thus available for WebLogic internal tasks.<span style="color: #ff0000"> </span></p>
<p>The threads in the &#8216;default&#8217; queue or the application specific thread queue (if one has been configured)<span style="color: #ff0000"> </span>are the threads that should be examined in the event of a server hang.<span style="color: #ff0000"> </span>Here’s an example of what one of these threads looks like in a thread dump. Execute Thread &#8216;14&#8242; from the &#8216;default&#8217; queue looks like in a thread dump when the thread is waiting for work. The latest method called by this thread is <span style="font-family: 'Courier New', Courier, mono;">Object.wait()</span>. This thread is in a state &#8220;waiting on monitor&#8221;.</td>
</tr>
</tbody>
</table>
<table style="width: 600px;" border="1" cellspacing="2" cellpadding="2" width="700">
<tbody>
<tr>
<td style="vertical-align: top; background-color: #cccccc" width="700"><span>&#8220;ExecuteThread: &#8216;14&#8242; for queue: &#8216;default&#8217;&#8221; daemon prio=5 tid=0&#215;8b0ab30 nid=0&#215;1f4 waiting on monitor [0x96af000..0x96afdc4]</span><br />
<span>at</span><br />
<span>java.lang.Object.wait(Native Method)</span><br />
<span>at</span><br />
<span>java.lang.Object.wait(Object.java:420)</span><br />
<span>at</span><br />
<span>weblogic.kernel.ExecuteThread.waitForRequest(ExecuteThread.java:94)</span><br />
<span>at</span><br />
<span>weblogic.kernel.ExecuteThread.run(ExecuteThread.java:118)</span></td>
</tr>
</tbody>
</table>
<table style="width: 600px; color: #ff0000; text-align: left;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top"><span style="color: #000000">Threads can be in one of several states.  Please see the <a href="#Analysis_of_Thread_Dump">table</a> below for a description of the thread states.</span><br />
<span style="color: #000000">The format of the thread dump varies with the vendor.  Check on the vendor&#8217;s website for information regarding the format. </span></p>
<p><span style="color: #000000">Below is an example of  threads that  may  be hanging.  ExecuteThread &#8216;9&#8242; is waiting to lock some object &lt;dde51520&gt;.   Notice the &#8220;waiting to lock &lt;dde51520&gt;&#8221; line in the stack trace for this thread.  ExecuteThread &#8216;6&#8242; is also &#8220;waiting to lock the same object &lt;dde51520&gt;&#8221;.  The third thread, ExecuteThread &#8216;5&#8242; has locked this object &lt;dde51520&gt;and is doing work.  This  example demonstrates why one thread dump is not enough.  If the server is hanging, and it is suspected that the cause is the locked object &lt;dde51520&gt;, then subsequent thread dumps will show whether or not that object was released and a new thread has locked object &lt;dde51520&gt;.  If after several thread dumps,  you do not see that the threads have progressed, that object &lt;dde51520&gt; has not been released, you may suspect that there is a problem with the routine(s) in the ExecuteThread &#8216;5&#8242; call stack because the lock is not being released.</span></td>
</tr>
</tbody>
</table>
<table style="width: 600px;" border="1" cellspacing="2" cellpadding="2" width="700">
<tbody>
<tr>
<td style="vertical-align: top; background-color: #cccccc" width="700"><span>&#8220;ExecuteThread: &#8216;9&#8242; for queue: &#8216;weblogic.kernel.Default&#8217;&#8221; daemon prio=5 tid=0xf684c8 nid=0&#215;13 waiting for monitor entry [cc2ff000..cc2ffc24]<br />
at weblogic.cluster.MemberManager.done(MemberManager.java:306)<br />
- waiting to lock &lt;dde51520&gt; (a weblogic.cluster.MemberManager)<br />
at weblogic.cluster.MulticastManager.execute(MulticastManager.java:399)<br />
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)<br />
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)</p>
<p>&#8220;ExecuteThread: &#8216;6&#8242; for queue: &#8216;weblogic.kernel.Default&#8217;&#8221; daemon prio=5 tid=0&#215;9df020 nid=0&#215;10 waiting for monitor entry [cc5ff000..cc5ffc24]<br />
at weblogic.cluster.MemberManager.getRemoteMembers(MemberManager.java:396)<br />
- waiting to lock &lt;dde51520&gt; (a weblogic.cluster.MemberManager)<br />
at weblogic.cluster.ClusterService.getRemoteMembers(ClusterService.java:238)<br />
at weblogic.servlet.internal.HttpServer.setServerList(HttpServer.java:388)<br />
at weblogic.servlet.internal.HttpServer.clusterMembersChanged(HttpServer.java:418)<br />
- locked &lt;ddf32360&gt; (a weblogic.servlet.internal.HttpServer)<br />
at weblogic.cluster.MemberManager$2.execute(MemberManager.java:421)<br />
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)<br />
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)</p>
<p>&#8220;ExecuteThread: &#8216;5&#8242; for queue: &#8216;weblogic.kernel.Default&#8217;&#8221; daemon prio=5 tid=0&#215;9df020 nid=0&#215;12 waiting for monitor entry [cc5ff000..cc5ffc24]<br />
. . .</p>
<p><span> at weblogic.cluster.MemberManager.checkTimeouts(MemberManager.java:346)<br />
- locked &lt;dde51520&gt; (a weblogic.cluster.MemberManager)<br />
at weblogic.cluster.MulticastManager.trigger(MulticastManager.java:291)<br />
at weblogic.time.common.internal.ScheduledTrigger.run(ScheduledTrigger.java:243 </span></p>
<p></span></td>
</tr>
</tbody>
</table>
<table style="width: 600px; text-align: left;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top">Determine if the&#8221;default&#8221; ExecuteThread queue is overloaded. Use the console to determine if any of the ExecuteThreads in the ‘default’ queue are idle. If none are idle, then the application probably needs to be configured with a larger number of ExecuteThreads. This value can be changed through the console and is in the <span style="font-family: 'Courier New', Courier, mono;">config.xml</span> file.</p>
<p>If the Execute Queue has idle threads, it is possible that not enough socket reader threads are allocated. By default, a WebLogic Server instance creates three socket reader threads upon booting. If a cluster system utilizes more than three sockets during peak periods, increase the number of socket reader threads.</p>
<p>The number of socket reader threads should usually be small. However, configure one thread for each Weblogic Server that acts as a client of the server instance that is hanging.</p>
<p>If using a JDBC connection pool, ensure that the JDBC connections have been configured to be equivalent to the number of simultaneous requests, i.e., execute threads, for the pool.</p>
<p><span><a href="#TOP">Top of Page</a></span></p>
<p><a name="Known_WebLogic_Server_Issues"></a><br />
The possibility exists that a problem with JDBC could produce deadlock. Check the version and service pack level of the server found in the beginning of the <span style="font-family: 'Courier New', Courier, mono;">weblogic.log</span>. Then check above the version and service pack lines for any temporary patches that have already been applied to the server classpath. The patches will tell what problems have already been addressed.</p>
<p><span><a href="#TOP">Top of Page</a></span></p>
<p><a name="Collecting_Thread_Dumps"></a><br />
The way to take a thread dump is dependent on the operating system where the hung server instance is installed. Information about taking a thread dump on various operating systems can be found at <a href="http://e-docs.bea.com/wls/docs81/cluster/trouble.html#gc">http://e-docs.bea.com/wls/docs81/cluster/trouble.html#gc</a>. Redirection of both standard error and standard out places the thread dump information in the proper context with server information and other messages and provides more useful logs.</p>
<p><em><strong>Unix Systems (Solaris, HP, AIX)</strong></em><br />
Use <span style="font-family: 'Courier New', Courier, mono;">kill –3 &lt;weblogic process id&gt;</span> to create the necessary thread dumps to diagnose a problem. Ensure this is done several times on each server, spaced about 5 to 10 seconds apart, to help diagnose deadlocks. For this to work, nohup the process when starting the server (refer to Solutions <a href="http://support.bea.com/application?namespace=askbea&amp;origin=ask_bea_answer.jsp&amp;event=link.view_answer_page_clfydoc&amp;answerpage=solution&amp;page=wls/S-12292.htm">S-12292</a> and <a href="http://support.bea.com/application?namespace=askbea&amp;origin=ask_bea_answer.jsp&amp;event=link.view_answer_page_clfydoc&amp;answerpage=solution&amp;page=wls/S-15924.htm">S-15924</a>).</p>
<p><em><strong>Windows, XP, NT</strong></em><br />
Each server requires <span style="font-family: 'Courier New', Courier, mono;">&lt;Ctrl&gt;-&lt;Break&gt;</span> to create the necessary thread dumps to diagnose a problem. Ensure this is done several times on each server, spaced about 5 to 10 seconds apart, to help diagnose deadlocks. On NT, in the command shell type <span style="font-family: 'Courier New', Courier, mono;">CTRL-Break</span>.</p>
<p>If you have installed WebLogic as a Windows service, you will not be able to see the messages from the JVM or WebLogic Server that are printed to standard out or standard error.  To view these messages, you must direct standard out and standard error to a file.  To do this, take the following steps:</p>
<ol>
<li>Create a backup copy of the <span style="font-family: 'Courier New', Courier, mono;">WL_HOME\server\bin\installSvc.cmd </span>master script.</li>
<li>In a text editor, open the <span style="font-family: 'Courier New', Courier, mono;">WL_HOME\server\bin\installSvc.cmd </span>master script.</li>
<li>In <span style="font-family: 'Courier New', Courier, mono;">installSvc.cmd</span>, the last command in the script invokes the <span style="font-family: 'Courier New', Courier, mono;">beasvc</span> utility.</li>
<li>At the end of the <span style="font-family: 'Courier New', Courier, mono;">beasvc </span>command, append the command <span style="font-family: 'Courier New', Courier, mono;">-log:&#8221;pathname&#8221;</span><br />
where pathname is a fully qualified path and filename of the file that you want to store the server&#8217;s standard out and standard error messages.</li>
<li>The modified <span style="font-family: 'Courier New', Courier, mono;">beasvc</span> command will resemble the following command:<br />
<span>&#8220;%WL_HOME%\server\bin\beasvc&#8221; -install </span><br />
<span>-svcname:&#8221;%DOMAIN_NAME%_%SERVER_NAME%&#8221; </span><br />
<span>-javahome:&#8221;%JAVA_HOME%&#8221; -execdir:&#8221;%USERDOMAIN_HOME%&#8221; </span><br />
<span>-extrapath:&#8221;%WL_HOME%\server\bin&#8221; -password:&#8221;%WLS_PW%&#8221; </span><br />
<span>-cmdline:%CMDLINE% </span><br />
<span>-log:&#8221;d:\bea\user_projects\domains\myWLSdomain\myWLSserver-stdout.txt&#8221; </span></li>
<li>If you started WebLogic with nohup, the log messages will show up in <span style="font-family: 'Courier New', Courier, mono;">nohup.out</span>.</li>
</ol>
<p><em><strong>Linux</strong></em><br />
The Linux operating system views threads differently than other operating systems. Each thread is seen by the operating system as a process. To take a thread dump on Linux, find the process id from which all the other processes were started. Use the commands:</p>
<ul>
<li>To obtain the root PID, use:<br />
<blockquote><p><span style="font-family: 'Courier New', Courier, mono;">ps -efHl | grep &#8216;java&#8217; **. ** </span></p></blockquote>
</li>
</ul>
<p>Use a grep argument that is a string that will be found in the process stack that matches the server startup command. The first PID reported will be the root process, assuming that the ps command has not been piped to another routine.</p>
<ul>
<li>Use the weblogic.Admin command <span style="font-family: 'Courier New', Courier, mono;">THREAD_DUMP</span></li>
</ul>
<p>Another method of getting a thread dump is to use the <span style="font-family: 'Courier New', Courier, mono;">THREAD_DUMP</span> admin command. This method is independent of the OS on which the server instance is running.</p>
<blockquote><p><span style="font-family: 'Courier New', Courier, mono;">java weblogic.Admin -url ManagedHost:8001 -username weblogic -password weblogic THREAD_DUMP</span></p></blockquote>
<p><strong>NOTE:</strong> This command cannot be used if unable to ping the server instance.</p>
<p>If the JVM in use is Sun’s, the thread dump goes to stdout. Sun has enhanced the thread dump format between JVM 1.3.1 and 1.4. To obtain Sun’s 1.4 style of thread dump add the following option to the java command line for starting the 1.3.1 JVM:</p>
<blockquote><p><span style="font-family: 'Courier New', Courier, mono;">-XX:+JavaMonitorsInStackTrace</span></p></blockquote>
<p><span><a href="#TOP">Top of Page</a></span></p>
<p><a name="Analysis_of_Thread_Dump"></a><br />
The most useful tool in analyzing a server hang is a set of thread dumps. A thread dump provides information on what each of the threads is doing at a particular moment in time. A set of thread dumps (usually 3 or more taken 5 to 10 seconds apart) can help analyze the change or lack of change in each thread’s state from one thread dump to another. A hung server thread dump would typically show little change in thread states from the first to the last dump.</p>
<p>Threads can be in one of the following states:</p>
<table style="width: 600px; height: 171px;" border="1">
<tbody>
<tr>
<td>Running or runnable thread</td>
<td>A runnable state means that the threads could be running or are running at that instance in time.</td>
</tr>
<tr>
<td>Suspended thread</td>
<td>Thread has been suspended by the JVM.</td>
</tr>
<tr>
<td>Thread waiting on a condition variable</td>
<td>Threads in a condition wait state can be thought of as waiting for an event to occur.</td>
</tr>
<tr>
<td>Thread waiting on a monitor lock</td>
<td>Monitors are used to manage access to code that should only be run by a single thread at a time</td>
</tr>
</tbody>
</table>
<p>More information on thread states can be found at<a href="http://java.sun.com/developer/onlineTraining/Programming/JDCBook/stack.html#states"> http://java.sun.com/developer/onlineTraining/Programming/JDCBook/stack.html#states.</a></p>
<p>There is also a thread analysis tool at <a href="http://dev2dev.bea.com/resourcelibrary/utilitiestools/adminmgmt.jsp">http://dev2dev.bea.com/resourcelibrary/utilitiestools/adminmgmt.jsp.</a><br />
Download the tool and read the instructions at the link.<br />
<strong><br />
What to Look at in the Thread Dump</strong><br />
All requests enter the WebLogic Server through the ListenThread. If the ListenThread is gone, no work can be received and therefore no work can be done. Verify that a ListenThread exists in the thread dump. The ListenThread should be in the socketAccept method. The following example shows what the Listen Thread looks like:</td>
</tr>
</tbody>
</table>
<table style="width: 600px;" border="1" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: #cccccc"><span>&#8220;ListenThread.Default&#8221; prio=10 tid=0&#215;00037888 nid=93 lwp_id=6888343 runnable [0x 1a81b000..0x1a81b530]</span> <span>at java.net.PlainSocketImpl.socketAccept(Native Method)</span><br />
<span>at</span><br />
<span>java.net.PlainSocketImpl.accept(PlainSocketImpl.java:353)</span><br />
<span>- locked &lt;0&#215;26d9d490&gt; (a java.net.PlainSocketImpl)</span><br />
<span>at</span><br />
<span>java.net.ServerSocket.implAccept(ServerSocket.java:439)</span><br />
<span>at</span><br />
<span>java.net.ServerSocket.accept(ServerSocket.java:410)</span><br />
<span>at</span><br />
<span>weblogic.socket.WeblogicServerSocket.accept(WeblogicServerSocket.java:24)</span><br />
<span>at</span><br />
<span>weblogic.t3.srvr.ListenThread.accept(ListenThread.java:713)</span><br />
<span>at</span><br />
<span>weblogic.t3.srvr.ListenThread.run(ListenThread.java:290)</span></td>
</tr>
</tbody>
</table>
<table style="width: 600px; text-align: left;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top">Socket Reader Threads accept the incoming request from the Listen Thread Queue and put it on the Execute Thread Queue. If there are no socket reader threads in the thread dump, then there is a bug somewhere that is causing the socket reader thread to vanish. There should always be at least 3 socket reader threads. One socket reader thread is usually in the poll function, while the other two are available to process requests. Below are Socket Reader threads from a sample thread dump.</td>
</tr>
</tbody>
</table>
<table style="width: 600px;" border="1" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: #cccccc"><span>&#8220;ExecuteThread: &#8216;2&#8242; for queue: &#8216;weblogic.socket.Muxer&#8217;&#8221; daemon prio=10 tid=0&#215;000</span> <span>36128 nid=75 lwp_id=6888070 waiting for monitor entry [0x1b12f000..0x1b12f530]</span><br />
<span>at</span><br />
<span>weblogic.socket.PosixSocketMuxer.processSockets(PosixSocketMuxer.java:92)</span><br />
<span>- waiting to lock &lt;0&#215;25c01198&gt; (a java.lang.String)</span><br />
<span>at</span><br />
<span>weblogic.socket.SocketReaderRequest.execute(SocketReaderRequest.java:32)</span><br />
<span>at</span><br />
<span>weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:178)</span><br />
<span>at</span><br />
<span>weblogic.kernel.ExecuteThread.run(ExecuteThread.java:151)</span></p>
<p><span>&#8220;ExecuteThread: &#8216;1&#8242; for queue: &#8216;weblogic.socket.Muxer&#8217;&#8221; daemon prio=10 tid=0&#215;000</span> <span>35fc8 nid=74 lwp_id=6888067 runnable [0x1b1b0000..0x1b1b0530]</span> <span>at weblogic.socket.PosixSocketMuxer.poll(Native Method)</span><br />
<span>at</span><br />
<span>weblogic.socket.PosixSocketMuxer.processSockets(PosixSocketMuxer.java:99)</span><br />
<span> &#8211; locked &lt;0&#215;25c01198&gt; (a java.lang.String)</span><br />
<span>at</span><br />
<span>weblogic.socket.SocketReaderRequest.execute(SocketReaderRequest.java:32)</span><br />
<span>at</span><br />
<span>weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:178)</span><br />
<span>at</span><br />
<span>weblogic.kernel.ExecuteThread.run(ExecuteThread.java:151)</span></p>
<p><span>&#8220;ExecuteThread: &#8216;0&#8242; for queue: &#8216;weblogic.socket.Muxer&#8217;&#8221; daemon prio=10 tid=0&#215;000</span> <span>35e68 nid=73 lwp_id=6888066 waiting for monitor entry [0x1b231000..0x1b231530]</span><br />
<span>at</span><br />
<span>weblogic.socket.PosixSocketMuxer.processSockets(PosixSocketMuxer.java:92)</span><br />
<span>- waiting to lock &lt;0&#215;25c01198&gt; (a java.lang.String)</span><br />
<span>at</span><br />
<span>weblogic.socket.SocketReaderRequest.execute(SocketReaderRequest.java:32)</span><br />
<span>at</span><br />
<span>weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:178)</span><br />
<span>a</span><span>t</span><br />
<span>weblogic.kernel.ExecuteThread.run(ExecuteThread.java:151)</span></td>
</tr>
</tbody>
</table>
<table style="width: 600px; text-align: left;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top">The <span style="font-family: 'Courier New', Courier, mono;">ThreadPoolPercentSocketReaders</span> attribute sets the maximum percentage of execute threads that are set to read messages from a java socket. The optimal value for this attribute is application-specific. The default value is 33, and the valid range is 1 to 99.</p>
<p>Allocating execute threads to act as socket reader threads increases the speed and the ability of the server to accept client requests. It is essential to balance the number of execute threads that are devoted to reading messages from a socket and those threads that perform the actual execution of tasks in the server.</p>
<p>In release 8.1, the socket reader threads no longer use &#8220;ExecuteThreads&#8221; in the default queue.  Instead they have their own thread group named.</p>
<p><strong>Next Steps</strong><br />
The next steps require a further analysis of the thread dump. Look in the thread dump to see what each the threads are doing at the time of the hang. This will help to analyze the next stage of the investigation. For example, if there are many threads involved in JSP compilation, refer to <a href="#Potential_Causes_of_Server_Hang">Potential Causes of Server Hang</a> for further diagnosis and actions to test.</p>
<p><span><a href="#TOP">Top of Page</a></span></td>
</tr>
</tbody>
</table>
<p><span style="text-decoration: underline;"><span style="color: #669966; font-size: x-small;"> </span></span></p>
<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/java_generic_server_hang.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

