亚洲大尺度无码无码专区,亚洲最大激情中文字幕,亚洲最大AV网站在线观看http://www.tkk7.com/leekiang/category/24431.htmlMDA/MDD/TDD/DDD/DDDDDDDzh-cnFri, 13 Jul 2012 17:32:54 GMTFri, 13 Jul 2012 17:32:54 GMT60線上解決Resin服務響應過慢的幾個方法(轉)http://www.tkk7.com/leekiang/archive/2012/07/13/383026.htmlleekiangleekiangFri, 13 Jul 2012 07:48:00 GMThttp://www.tkk7.com/leekiang/archive/2012/07/13/383026.htmlhttp://www.tkk7.com/leekiang/comments/383026.htmlhttp://www.tkk7.com/leekiang/archive/2012/07/13/383026.html#Feedback0http://www.tkk7.com/leekiang/comments/commentRss/383026.htmlhttp://www.tkk7.com/leekiang/services/trackbacks/383026.html

1、查看服務器網絡狀態TIME_WAIT的數量。

#netstat -antp|grep -i time_wait|wc -l查看TIME_WAIT數量,如果數量過多,并且Resin前端還有Nginx或者Apache,那么請把socket-timeout、keepalive-max和把keepalive-timeout調小

????? <socket-timeout>30s</socket-timeout>
????? <keepalive-max>512</keepalive-max>
????? <keepalive-timeout>60s</keepalive-timeout>

2、查看JVM中對象占用內存情況

jmap 能查看jvm內存中,對象占用內存的情況,還提供非常方便的命令將jvm的內存信息導出的文件。

#jmap -dump:format=b,file=heap.bin <pid>?

命令jhat 能夠解析 java內存堆的文件,生成相關信息,并啟動webServer提供查詢。 也就說,我們可以通過瀏覽器來看這些內存信息。jhat還提供了一個類sql的查詢語言---OQL來給我們使用。

#jhat -J-Xmx512m heap.bin????

就可以將我們剛剛使用jmap導出的內存信息交給jhat解析了。默認的情況下,它會監聽7000端口。我在本機的地址就是,http://localhost:7000/。
訪問http://localhost:7000/histo/,大致可以看到一下的畫面,這里列出對象,對象實例數量、總占用內存大小。點擊進去之后可以看到“誰引用了這個對象,這個對象又引用了哪個”這些信息。不過因為展示的信息非常多,并沒有想象中那樣清晰可見。

3、dump獲取java stack和native stack信息

消息隊列會突然堵塞,查看消費者日志,發現處理延時明顯延長,而此時網絡無丟包。最后多方排查,是java消費者運行出現死鎖。
這種問題可以通過jstack來dump獲取java stack和native stack信息查明問題。

#jstatck <pid>




leekiang 2012-07-13 15:48 發表評論
]]>
tomcat5中include jsp后輸出的網頁出現亂碼的解決辦法(轉)http://www.tkk7.com/leekiang/archive/2012/03/03/371182.htmlleekiangleekiangSat, 03 Mar 2012 15:26:00 GMThttp://www.tkk7.com/leekiang/archive/2012/03/03/371182.htmlhttp://www.tkk7.com/leekiang/comments/371182.htmlhttp://www.tkk7.com/leekiang/archive/2012/03/03/371182.html#Feedback0http://www.tkk7.com/leekiang/comments/commentRss/371182.htmlhttp://www.tkk7.com/leekiang/services/trackbacks/371182.html一個BUG的快速解決方法.希望能給大家的一些啟示
朋友打來電話,他們公司新裝了TOMCAT5,然后在編譯JSP時,被INCLUDE的JSP都出現了問題.就是編譯后被INCLUDE的地方多了兩個"??"而其它正常,而如果手工把被INCLUDE的內容COPY上去測沒有問題.
他們的工程師都不知道是什么問題,因為周一要發布出去,所以非常著急.

我不知道大家聽到這種情況會如何,我知道大多數人比我聰明,你肯定想到了,所以你沒有必要再看了.我下面的內容只是對沒有想到的人而言.

其實他電話還沒打完 ,我就知道問題99%是他的jsp在編輯的時候是存為UTF-8而不是ANSI格式,否則沒有道理出現這種問題,事實正是如此,我讓他用UE打開看看果然前面多了幾個UTF字符.

重要的是TOMCAT這種容器竟然有這樣的BUG,不能正確讀取UTF-8格式的文件,你總不能強求用戶編輯JSP文件時一定要存為什么格式吧?
費話少說,下載tomcat5的src,進入jakarta-tomcat-jasper\jasper2\src\share\org\apache\jasper\compiler,找到JspUtil.java,找到
public static InputStream getInputStream(String fname, JarFile jarFile,
JspCompilationContext ctxt,
ErrorDispatcher err)
throws JasperException, IOException {

InputStream in = null;

if (jarFile != null) {
String jarEntryName = fname.substring(1, fname.length());
ZipEntry jarEntry = jarFile.getEntry(jarEntryName);
if (jarEntry == null) {
err.jspError("jsp.error.file.not.found", fname);
}
in = jarFile.getInputStream(jarEntry);
} else {
in = ctxt.getResourceAsStream(fname);
}

if (in == null) {
err.jspError("jsp.error.file.not.found", fname);
}
return in;
}

在return in前加上判斷,改成:
public static InputStream getInputStream(String fname, JarFile jarFile,
JspCompilationContext ctxt,
ErrorDispatcher err)
throws JasperException, IOException {

InputStream in = null;

if (jarFile != null) {
String jarEntryName = fname.substring(1, fname.length());
ZipEntry jarEntry = jarFile.getEntry(jarEntryName);
if (jarEntry == null) {
err.jspError("jsp.error.file.not.found", fname);
}
in = jarFile.getInputStream(jarEntry);
} else {
in = ctxt.getResourceAsStream(fname);
}

if (in == null) {
err.jspError("jsp.error.file.not.found", fname);
}
PushbackInputStream testin = new PushbackInputStream(in);
int ch = testin.read();
if (ch != 0xef) {
testin.unread(ch);
}
else if ((ch = testin.read()) != 0xbb) {
testin.unread(ch);
testin.unread(0xef);
}
else if ((ch = testin.read()) != 0xbf) {
throw new IOException("錯誤的UTF-8格式文件");
}
else{
//fStream.setEncoding("UTF-8");
testin.read();
}
return testin;
}

編譯,重新打包,替換原來的包,運行TOMCAT,OK!

整個問題解決除了遠程登錄他的服務器傳送文件的時間,總共只有4-5分鐘.其實只要問題定位準確,就不難解決了.我一再強調的是經熟悉底層,你如果知道內 存中每個byte從哪兒來要到哪兒去,就可以非常容易地解決問題.在此之前我連TOMCAT5下載都沒有下過,更別說試用了.但只要你對JDK有深入的了 解,就可以準確地定位問題的所在.

希望本文能給不是高手的朋友一點幫助和啟發,對于高手的朋友你可以棄之一笑.


UTF-8文件的Unicode簽名BOM(Byte Order Mark)問題
utf-8編碼include頁面空格
Django下碰到EF BB BF問題
php utf-8編碼include頁面空格

leekiang 2012-03-03 23:26 發表評論
]]>
關于resinhttp://www.tkk7.com/leekiang/archive/2011/04/19/348584.htmlleekiangleekiangTue, 19 Apr 2011 09:37:00 GMThttp://www.tkk7.com/leekiang/archive/2011/04/19/348584.htmlhttp://www.tkk7.com/leekiang/comments/348584.htmlhttp://www.tkk7.com/leekiang/archive/2011/04/19/348584.html#Feedback0http://www.tkk7.com/leekiang/comments/commentRss/348584.htmlhttp://www.tkk7.com/leekiang/services/trackbacks/348584.html?? 還有一個辦法,我沒試過:在<host id="" root-directory=".">標記中找到</web-app>在這個標記后面手動添加一行配置 <web-app id="/項目名稱" root-directory="deploy/項目名稱"/>

2,resin2.1.17 官方下載地址
官網上已經沒有相關下載鏈接,但是文件還在,趁早下吧,用3以上版本就得付費買證書了
Linux:http://caucho.com/download/resin-2.1.17.tar.gz
win:http://caucho.com/download/resin-2.1.17.zip
好像resin2的最后一個版本是2.1.18

3,
resin2.x支持JSP 1.2/Servlet 2.3
3.X支持JSP 2.0/Servlet 2.4
3.03不需要許可證
3.04開始需要許可證


4,仔細翻看了Resin2和Resin3的resin.conf文件例子發現Resin2系列采用了資源定義的方式統一化的定義各種雷動的配置,而Resin3則把它省略成直接用res-ref-name作為限定標識的形式,這樣的利弊很容易看出:
利:調用配置方便程序可以更簡潔的讀取配置,同時使配置更為簡潔。
弊:這樣的形式雖然使程序簡潔,配置方便但同時帶來了程序上管理更為復雜每個資源定義名的判斷都需單獨判斷而不能在程序內統一判斷

5,
要想讓resin能夠動態加載class,要三個條件,1.高版本的resin? 2.與之相匹配的jdk 3.以-Xdebug方式啟動。來源

6,
resin.conf里面有一段內容如下所示:
? <!--
???? - Ping to test if the web server is still up.? You can uncomment this
???? - and point it to pages on the webserver that exercise your main
???? - logic (like database access).? If the GET fails, it will restart
???? - the server.? This will catch deadlocks, but not JDK freezes.
???? - <ping sleep-time=’1m’ retry-count=’3’ retry-time=’1s’>
???? -?? <url>http://localhost:8080/ping/ping.jsp</url>
???? - </ping>
?? -->
這段內容默認情況下是被注釋的。它的功能是讓Resin每隔一分鐘就測試一下能否訪問/ping/ping.jsp文件,測試時間是1s,如果不成功,就重試三次。如果三次都不成功,Resin就自動重啟。

7,
報錯:sun.tools.javac.Main 已過時
配置文件中的
<java compiler=”internal" compiler-args="" />
改為:
<java compiler="javac" compiler-args="" />

8,resin2和resin3配置的部分區別
1)使用datasource時,resin3好像需要把mysql驅動放到resin3\lib下,而resin2只需要放到web應用的lib下?
2)
resin2:<web-app id='/' app-dir='C:/resin2/webapps/blog'>
resin3:<web-app id='/' document-directory='C:/resin3/deploy/blog'>
3)數據源
resin2:
<resource-ref><res-ref-name>jdbc/blog</res-ref-name><res-type>javax.sql.DataSource</res-

type><init-param driver-name="com.mysql.jdbc.Driver"/><init-param

url="jdbc:mysql://127.0.0.1:3306/blog?useUnicode=true&amp;characterEncoding=UTF-8"/><init-

param user="blog"/><init-param password="blog" /><init-param max-connections="50"/><init-

param max-idle-time="50"/></resource-ref>

resin3:
? <database><jndi-name>jdbc/blog</jndi-name><driver type="com.mysql.jdbc.Driver">?????
<url>jdbc:mysql://127.0.0.1:3306/blog?useUnicode=true&amp;characterEncoding=UTF-8</url><user>blog</user><password>blog</password></driver></database>

9,myeclipse下使用resin調試jsp
修改resin.conf:
<javac compiler="internal" args="-g -source 1.5"/>
加上-g就行了。
好像resin2不行

18,

TOMCAT與Resin之比較
Apache+resin系統按路徑分發的實現及其負載均衡中的session機制
Resin與apache整合實現負載均衡
關于resin的 session 的持久化


leekiang 2011-04-19 17:37 發表評論
]]>
Adding Socket Timeout to java.net.URLConnection (JDK 1.2)http://www.tkk7.com/leekiang/archive/2010/04/14/318278.htmlleekiangleekiangWed, 14 Apr 2010 09:09:00 GMThttp://www.tkk7.com/leekiang/archive/2010/04/14/318278.htmlhttp://www.tkk7.com/leekiang/comments/318278.htmlhttp://www.tkk7.com/leekiang/archive/2010/04/14/318278.html#Feedback0http://www.tkk7.com/leekiang/comments/commentRss/318278.htmlhttp://www.tkk7.com/leekiang/services/trackbacks/318278.htmlAdding Socket Timeout to java.net.URLConnection (JDK 1.2)

found a bug , see "connected = true;" in public void connect() throws IOException {


Note: 05/11/01 Sam Found a patch for borland

As I got the email:

Just writing to inform you theis patch for 1.3 works with the 1.3 shipped with borland JBuilder 4 (not sure which excat version it is)

the only problems I had where that the code was a bit messed up, following are the changes made to it to make it work.

				
public void SetTimeout(int i)
throws SocketException
{
this.timeout = i; // Should be i not -1 <------------ERROR
serverSocket.setSoTimeout(i) ;
}

public boolean parseHTTP(MessageHeader header, ProgressEntry entry)
throws java.io.IOException
{
if( this.timeout != -1 ) {
try {
serverSocket.setSoTimeout(timeout) ; // should be timeout not i <---------------ERROR
} catch( SocketException e ) {
throw new java.io.IOException("unable to set socket timeout!") ;
}
}

return super.parseHTTP(header, entry) ;
}
Sam

Under JDK 1.3, which is HTTP 1.1 compatible, the InterruptedIOException gets caught by the socket I/O routines and ignored. input is read in "chunks". I debugged the existing code under 1.3, the Timeout is getting set properly etc., but the exception gets caught in the underlying I/O routines, which have a single retry if any IOExceptions are thrown. Thanks a lot Sun....

3/22/01: Patch for JDK 1.3 unverified

Patch code for JDK 1.3 from Matt Ho (unverified)

				
----[ snip ]----

import sun.net.www.MessageHeader ;
import sun.net.ProgressEntry ;

.
.
.

private int timeout = -1 ;

public void SetTimeout(int i)
throws SocketException
{
this.timeout = -1 ;
serverSocket.setSoTimeout(i) ;
}

public boolean parseHTTP(MessageHeader header, ProgressEntry entry)
throws java.io.IOException
{
if( this.timeout != -1 ) {
try {
serverSocket.setSoTimeout(i) ;
} catch( SocketException e ) {
throw new java.io.IOException("unable to set socket timeout!") ;
}
}

return super.parseHTTP(header, entry) ;
}

----[ snip ]----

On with the rest of the stuff

The BSD socket API supports a timeout option (the option is SO_TIMEOUT), which is also supported in java.net.socket. Unfortunately, java.net.URLConnection does not expose the underlying socket. So if you have a URL connection that attempts to connect to a dead URL (i.e., the URL is well formed and exists but the site is down), the socket will eventually timeout using the operating system's default timeout (420 seconds on Win NT). The timeout is a very long time, e.g., for spiders or URL checking.

The following files illustrate a technique to introduce a socket timeout to URL connection, based upon the actual java source code itself (see the open source community licensing at JavaSoft).

The Base classes, or URLConnection internals

Java's implementation of networking is protocol independent, as well as object oriented. Therefore the implementation is not as straightfoward as one might imagine.

URLConnection relies upon several internal classes using a client/server model as well as a "factory" design pattern. The client's base class is sun.net.www.http.HttpClient. This class is extended for the purpose of exposing the socket.

The default factory is URLStreamHandlerFactory, which indirectly "handles" the creation of an HTTP client by instantiating a class that is specific to the HTTP protocol: sun.net.www.protocol.http.Handler. The handler actually creates the client.

In practice, the factory is only necessary to mimic java's implementation, but only the Handler is really needed.

Derived Classes

We derive 4 classes so as to preserve the symmetry with the java source code:

HttpURLConnectionTimeout extends sun.net.www.protocol.http.HttpURLConnection
HttpTimeoutHandler extends sun.net.www.protocol.http.Handler
HttpTimeoutFactory implements java.net.URLStreamHandlerFactory
HttpClientTimeout extends sun.net.www.http.HttpClient

On with the source code.


HttpURLConnectionTimeout

// whatever package you want
import sun.net.www.http.HttpClient;
import java.net.*;
import java.io.*;
public class HttpClientTimeout extends HttpClient
{
public HttpClientTimeout(URL url, String proxy, int proxyPort) throws IOException
{
super(url, proxy, proxyPort);
}

public HttpClientTimeout(URL url) throws IOException
{
super(url, null, -1);
}

public void SetTimeout(int i) throws SocketException {
serverSocket.setSoTimeout(i);
}

/* This class has no public constructor for HTTP. This method is used to
* get an HttpClient to the specifed URL. If there's currently an
* active HttpClient to that server/port, you'll get that one.
*
* no longer syncrhonized -- it slows things down too much
* synchronize at a higher level
*/
public static HttpClientTimeout GetNew(URL url)
throws IOException {
/* see if one's already around */
HttpClientTimeout ret = (HttpClientTimeout) kac.get(url);
if (ret == null) {
ret = new HttpClientTimeout (url); // CTOR called openServer()
} else {
ret.url = url;
}
// don't know if we're keeping alive until we parse the headers
// for now, keepingAlive is false
return ret;
}

public void Close() throws IOException
{
serverSocket.close();
}

public Socket GetSocket()
{
return serverSocket;
}


}

HttpTimeoutFactory

import java.net.*;

public class HttpTimeoutFactory implements URLStreamHandlerFactory
{
int fiTimeoutVal;
public HttpTimeoutFactory(int iT) { fiTimeoutVal = iT; }
public URLStreamHandler createURLStreamHandler(String str)
{
return new HttpTimeoutHandler(fiTimeoutVal);
}

}

HttpTimeoutHandler

import java.net.*;
import java.io.IOException;

public class HttpTimeoutHandler extends sun.net.www.protocol.http.Handler
{
int fiTimeoutVal;
HttpURLConnectionTimeout fHUCT;
public HttpTimeoutHandler(int iT) { fiTimeoutVal = iT; }

protected java.net.URLConnection openConnection(URL u) throws IOException {
return fHUCT = new HttpURLConnectionTimeout(u, this, fiTimeoutVal);
}

String GetProxy() { return proxy; } // breaking encapsulation
int GetProxyPort() { return proxyPort; } // breaking encapsulation

public void Close() throws Exception
{
fHUCT.Close();
}

public Socket GetSocket()
{
return fHUCT.GetSocket();
}
}

HttpURLConnectionTimeout

import java.net.*;
import java.io.*;
import sun.net.www.http.HttpClient;

public class HttpURLConnectionTimeout extends sun.net.www.protocol.http.HttpURLConnection
{
int fiTimeoutVal;
HttpTimeoutHandler fHandler;
HttpClientTimeout fClient;
public HttpURLConnectionTimeout(URL u, HttpTimeoutHandler handler, int iTimeout) throws IOException
{
super(u, handler);
fiTimeoutVal = iTimeout;
}

public HttpURLConnectionTimeout(URL u, String host, int port) throws IOException
{
super(u, host, port);
}

public void connect() throws IOException {
if (connected) {
return;
}
try {
if ("http".equals(url.getProtocol()) /* && !failedOnce <- PRIVATE */ ) {
// for safety's sake, as reported by KLGroup
synchronized (url)
{
http = HttpClientTimeout.GetNew(url);
}
fClient = (HttpClientTimeout)http;
((HttpClientTimeout)http).SetTimeout(fiTimeoutVal);
} else {
// make sure to construct new connection if first
// attempt failed
http = new HttpClientTimeout(url, fHandler.GetProxy(), fHandler.GetProxyPort());
}
ps = (PrintStream)http.getOutputStream();
} catch (IOException e) {
throw e; }
// this was missing from the original version
connected = true;
}

/**
* Create a new HttpClient object, bypassing the cache of
* HTTP client objects/connections.
*
* @param url the URL being accessed
*/
protected HttpClient getNewClient (URL url)
throws IOException {
HttpClientTimeout client = new HttpClientTimeout (url, (String)null, -1);
try {
client.SetTimeout(fiTimeoutVal);
} catch (Exception e)
{ System.out.println("Unable to set timeout value"); }
return (HttpClient)client;
}

/**
* opens a stream allowing redirects only to the same host.
*/
public static InputStream openConnectionCheckRedirects(URLConnection c)
throws IOException
{
boolean redir;
int redirects = 0;
InputStream in = null;

do {
if (c instanceof HttpURLConnectionTimeout) {
((HttpURLConnectionTimeout) c).setInstanceFollowRedirects(false);
}

// We want to open the input stream before
// getting headers, because getHeaderField()
// et al swallow IOExceptions.
in = c.getInputStream();
redir = false;

if (c instanceof HttpURLConnectionTimeout) {
HttpURLConnectionTimeout http = (HttpURLConnectionTimeout) c;
int stat = http.getResponseCode();
if (stat >= 300 && stat <= 305 &&
stat != HttpURLConnection.HTTP_NOT_MODIFIED) {
URL base = http.getURL();
String loc = http.getHeaderField("Location");
URL target = null;
if (loc != null) {
target = new URL(base, loc);
}
http.disconnect();
if (target == null
|| !base.getProtocol().equals(target.getProtocol())
|| base.getPort() != target.getPort()
|| !HostsEquals(base, target)
|| redirects >= 5)
{
throw new SecurityException("illegal URL redirect");
}
redir = true;
c = target.openConnection();
redirects++;
}
}
} while (redir);
return in;
}

// Same as java.net.URL.hostsEqual


static boolean HostsEquals(URL u1, URL u2)
{
final String h1 = u1.getHost();
final String h2 = u2.getHost();

if (h1 == null) {
return h2 == null;
} else if (h2 == null) {
return false;
} else if (h1.equalsIgnoreCase(h2)) {
return true;
}
// Have to resolve addresses before comparing, otherwise
// names like tachyon and tachyon.eng would compare different
final boolean result[] = {false};

java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
try {
InetAddress a1 = InetAddress.getByName(h1);
InetAddress a2 = InetAddress.getByName(h2);
result[0] = a1.equals(a2);
} catch(UnknownHostException e) {
} catch(SecurityException e) {
}
return null;
}
});

return result[0];
}

void Close() throws Exception
{
fClient.Close();
}

Socket GetSocket()
{
return fClient.GetSocket();
}
}

Sample Usage #1

import java.net.*;
public class MainTest
{

public static void main(String args[])
{
int i = 0;
try {
URL theURL = new URL((URL)null, "http://www.snowball.com", new HttpTimeoutHandler(150)); // timeout value in milliseconds

// the next step is optional
theURL.setURLStreamHandlerFactory(new HttpTimeoutFactory(150));


URLConnection theURLconn = theURL.openConnection();
theURLconn.connect();
i = theURLconn.getContentLength();
}
catch (InterruptedIOException e)
{
System.out.println("timeout on socket");
}
System.out.println("Done, Length:" + i);
}
}

Sample Usage #2

		try
{
HttpTimeoutHandler xHTH = new HttpTimeoutHandler(10); // timeout value in milliseconds
URL theURL = new URL((URL)null, "http://www.javasoft.com", xHTH);
HttpURLConnection theUC = theURL.openConnection();
.
.
.
}
catch (InterruptedIOException e)
{
// socket timed out

}

Some remarks: this code is thread safe.

More to come

來源:http://www.logicamente.com/sockets.html

???? http://www.edevs.com/java-programming/15068/


Thanks Felipe!

If I understand information at http://www.logicamente.com/sockets.html correctly there are 2 problems with timeout when using HttpURLConnection in JDK 1.3:

1. HttpURLConnection does not allow changing the default timeout that is in order of few minutes.

2. If actual HTTP stream is chunked then HttpURLConnection ignores even the default timeout and tries to read what it perceives as a continued stream resulting in indefinite read wait.

The patch shown at the above URL, consisting of subclassing of 4 system classes (1 from java.net... and 3 from sun.net.www...), is aimed to resolve problem 1 above but does not help in problem 2.

My main problem is to have timeout when reading chunked stream (system default timeout will be ok to beginning with) and therefore the question is if this bug has been corrected in later versions of JDK? Thanks.

-----

I have seen much chat about this "problem", that is setSoTimeout not available or not working properly.

how about you write your own Timer (resettable) or 1.4 has Timer class

you just reset it anytime you detect network activity and close the Socket if the Timer finishes its cycle?



leekiang 2010-04-14 17:09 發表評論
]]>
HttpURLConnection timeout solutionhttp://www.tkk7.com/leekiang/archive/2010/04/14/318274.htmlleekiangleekiangWed, 14 Apr 2010 09:04:00 GMThttp://www.tkk7.com/leekiang/archive/2010/04/14/318274.htmlhttp://www.tkk7.com/leekiang/comments/318274.htmlhttp://www.tkk7.com/leekiang/archive/2010/04/14/318274.html#Feedback0http://www.tkk7.com/leekiang/comments/commentRss/318274.htmlhttp://www.tkk7.com/leekiang/services/trackbacks/318274.htmlFrom: Niels Campbell (niels_campbell_at_lycos.co.uk)
Date: 01/23/04
Date: 23 Jan 2004 09:14:16 -0800
After spending nearly 3 days on this problem to come up with a

solution I think it is only right to post the solution.

I found that you can't set the soTimeout on an HttpURLConnection as
the sockets are encapsulated within the HttpURLConnection
implementation.

I found Mike Reiche solution in which he uses a handler to set a
timeout value. This nearly worked. Looking at the code in the rt.jar I
found that the initial timeout was working, but the call
parseHTTP(...) in HttpClient was then attempting a second connection
which had a time out value of 0(infinite).

I modified the code to override the doConnect() in the NetworkClient
and managed to get a timeout occurring. To be exact two timeouts
occur.

It works on
java version "1.4.0_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_03-b04)
Java HotSpot(TM) Client VM (build 1.4.0_03-b04, mixed mode)
and
java version "1.2.2"
Classic VM (build JDK-1.2.2_013, native threads, symcjit)

Anyway here is the code, excuse the formatting.

/* HttpTimeoutURLConnection.java */
import java.net.*;
import java.io.*;
import sun.net.www.http.HttpClient;

// Need to override any function in HttpURLConnection that create a
new HttpClient
// and create a HttpTimeoutClient instead. Those functions are
// connect(), getNewClient(), getProxiedClient()

public class HttpTimeoutURLConnection extends
sun.net.www.protocol.http.HttpURLConnection
{

????public HttpTimeoutURLConnection(URL u, HttpTimeoutHandler handler,
int iSoTimeout)
????????throws IOException
????{
????????super(u, handler);
????????HttpTimeoutClient.setSoTimeout(iSoTimeout);
????}

????public void connect() throws IOException
????{
????????if (connected)
????????{
????????????return;
????????}

????????try
????????{
????????????if ("http".equals(url.getProtocol())) // && !failedOnce <-
PRIVATE
????????????{
????????????????// for safety's sake, as reported by KLGroup
????????????????synchronized (url)
????????????????{
????????????????????http = HttpTimeoutClient.getNew(url);
????????????????}
????????????}
????????????else
????????????{
????????????????if (handler instanceof HttpTimeoutHandler)
????????????????{
????????????????????http = new HttpTimeoutClient(super.url,
((HttpTimeoutHandler)handler).getProxy(),
((HttpTimeoutHandler)handler).getProxyPort());
????????????????}
????????????????else
????????????????{
????????????????????throw new IOException("HttpTimeoutHandler
expected");
????????????????}
????????????}

????????????ps = (PrintStream)http.getOutputStream();
????????}
????????catch (IOException e)
????????{
????????????throw e;
????????}

????????connected = true;
????}

????protected HttpClient getNewClient(URL url)
????????throws IOException
????{
????????HttpTimeoutClient httpTimeoutClient = new HttpTimeoutClient
(url, (String)null, -1);
????????return httpTimeoutClient;
????}

????protected HttpClient getProxiedClient(URL url, String s, int i)
????????throws IOException
????{
????????HttpTimeoutClient httpTimeoutClient = new HttpTimeoutClient
(url, s, i);
????????return httpTimeoutClient;
????}

}

/* HttpTimeoutHandler.java */
import java.net.*;
import java.io.IOException;

public class HttpTimeoutHandler extends
sun.net.www.protocol.http.Handler
{
????private int iSoTimeout=0;

????public HttpTimeoutHandler(int iSoTimeout)
????{
????????// Divide the time out by two because two connection attempts
are made
????????// in HttpClient.parseHTTP()

????????if (iSoTimeout%2!=0)
????????{
????????????iSoTimeout++;
????????}
????????this.iSoTimeout = (iSoTimeout/2);
????}

????protected java.net.URLConnection openConnection(URL u) throws
IOException
????{
????????return new HttpTimeoutURLConnection(u, this, iSoTimeout);
????}

????protected String getProxy()
????{
????????return proxy;
????}

????protected int getProxyPort()
????{
????????return proxyPort;
????}
}

/* HttpTimeoutFactory.java */
import java.net.*;

public class HttpTimeoutFactory implements URLStreamHandlerFactory
{
????private int iSoTimeout=0;

????public HttpTimeoutFactory(int iSoTimeout)
????{
????????this.iSoTimeout = iSoTimeout;
????}

????public URLStreamHandler createURLStreamHandler(String str)
????{
????????return new HttpTimeoutHandler(iSoTimeout);
????}
}

/* HttpTimeoutClient.java */
import sun.net.www.http.HttpClient;
import java.net.*;
import sun.net.*;
import sun.net.www.*;
import java.io.*;

public class HttpTimeoutClient extends HttpClient
{
????private static int iSoTimeout=0;

????public HttpTimeoutClient(URL url, String proxy, int proxyPort)
throws IOException
????{
????????super(url, proxy, proxyPort);
????}

????public HttpTimeoutClient(URL url) throws IOException
????{
????????super(url, null, -1);
????}

????public static HttpTimeoutClient getNew(URL url)
????????throws IOException
????{
????????HttpTimeoutClient httpTimeoutClient = (HttpTimeoutClient)
kac.get(url);

????????if (httpTimeoutClient == null)
????????{
????????????httpTimeoutClient = new HttpTimeoutClient (url); // CTOR
called openServer()
????????}
????????else
????????{
????????????httpTimeoutClient.url = url;
????????}

????????return httpTimeoutClient;
????}

????public static void setSoTimeout(int iNewSoTimeout)
????{
????????iSoTimeout=iNewSoTimeout;
????}

????public static int getSoTimeout()
????{
????????return iSoTimeout;
????}

????// Override doConnect in NetworkClient

????protected Socket doConnect(String s, int i)
????????throws IOException, UnknownHostException, SocketException
????{
????????Socket socket=super.doConnect(s,i);

????????// This is the important bit
????????socket.setSoTimeout(iSoTimeout);
????????return socket;
????}

}

/* Example use */
import java.util.*;
import java.io.*;
import java.net.*;

public class SystemProperty
{
????public static void main(String[] args)
????{
????????String sSoapUrl=" ????????System.out.println("Connecting to [" + sSoapUrl + "]");

????????URLConnection urlConnection = null;
????????URL url=null;

????????try
????????{
????????????url = new URL((URL)null, sSoapUrl, new
HttpTimeoutHandler(10000));
????????????urlConnection = url.openConnection();

????????????// Optional
????????????url.setURLStreamHandlerFactory(new
HttpTimeoutFactory(10000));

????????????System.out.println("Url class
["+urlConnection.getClass().getName()+"]");
????????}
????????catch (MalformedURLException mue)
????????{
????????????System.out.println(">>MalformedURLException<<");
????????????mue.printStackTrace();
????????}
????????catch (IOException ioe)
????????{
????????????System.out.println(">>IOException<<");
????????????ioe.printStackTrace();
????????}

????????HttpURLConnection httpConnection =
(HttpURLConnection)urlConnection;
????????System.out.println("Connected to [" + sSoapUrl + "]");

????????byte[] messageBytes=new byte[10000];
????????for (int i=0; i<10000; i++)
????????{
????????????messageBytes[i]=80;
????????}

????????try
????????{
????????????httpConnection.setRequestProperty("Connection", "Close");
????????????httpConnection.setRequestProperty("Content-Length",
String.valueOf(messageBytes.length));
????????????httpConnection.setRequestProperty("Content-Type",
"text/xml; charset=utf-8");
????????????httpConnection.setRequestMethod("POST");
????????????httpConnection.setDoOutput(true);
????????????httpConnection.setDoInput(true);
????????}
????????catch (ProtocolException pe)
????????{
????????????System.out.println(">>ProtocolException<<");
????????????pe.printStackTrace();
????????}

????????OutputStream outputStream=null;

????????try
????????{
????????????System.out.println("Getting output stream");
????????????outputStream =httpConnection.getOutputStream();
????????????System.out.println("Got output stream");

????????????outputStream.write(messageBytes);
????????}
????????catch (IOException ioe)
????????{
????????????System.out.println(">>IOException<<");
????????????ioe.printStackTrace();
????????}

????????try
????????{
????????????System.out.println("Getting input stream");
????????????InputStream is=httpConnection.getInputStream();
????????????System.out.println("Got input stream");

????????????byte[] buf = new byte[1000];
????????????int i;

????????????while((i = is.read(buf)) > 0)
????????????{
????????????????System.out.println(""+new String(buf));
????????????}
????????????is.close();
????????}
????????catch (Exception ie)
????????{
????????????ie.printStackTrace();
????????}

????}
}

Cheers,
Niels

來源:http://coding.derkeiler.com/Archive/Java/comp.lang.java.programmer/2004-01/3271.html
???? http://www.weblogicfans.net/viewthread.php?tid=1101
???? http://forums.sun.com/thread.jspa?threadID=568948
備注:在HttpTimeoutClient類中的第二個構造函數中的:super(url,null,-1)改為super(url, (String)null,-1)即可。


leekiang 2010-04-14 17:04 發表評論
]]>
weblogic上HttpURLConnection的超時http://www.tkk7.com/leekiang/archive/2010/04/14/318272.htmlleekiangleekiangWed, 14 Apr 2010 08:59:00 GMThttp://www.tkk7.com/leekiang/archive/2010/04/14/318272.htmlhttp://www.tkk7.com/leekiang/comments/318272.htmlhttp://www.tkk7.com/leekiang/archive/2010/04/14/318272.html#Feedback0http://www.tkk7.com/leekiang/comments/commentRss/318272.htmlhttp://www.tkk7.com/leekiang/services/trackbacks/318272.htmlSystem.setProperty("sun.net.client.defaultReadTimeout", "500");
在jdk1.4.2_05下測http,上面的代碼是生效的,https沒有試。
好像jdk1.4.2.12解決了https的問題,見jdk1.4的bug清單。
HttpURLConnection的實現類正常情況下是sun.net.www.protocol.http.HttpURLConnection
而weblogic8下是weblogic.net.http.SOAPHttpURLConnection。
SOAPHttpURLConnection是weblogic.net.http.HttpURLConnection的子類
System.setProperty("weblogic.client.SocketConnectTimeoutInSecs", "500");在sp4不管用
-Dweblogic.client.SocketConnectTimeoutInSecs=500也不管用。

在http://forums.oracle.com/forums/thread.jspa?threadID=766767里有人說
Well, it depends on the OS and JVM used. If Weblogic is using Native library (socket Muxer) for remote communication then socketconnectTimeout only helps when thread is stuck on "Socket.connect() method, but it would never timeout the socket if it is stuck on "Socket.read()" because the Control does not return to JVM till OS level TCP/IP connection returns.
To resolve this issue, try to timeout TCP connections at OS level using OS parameters. Hopefully BEA would come with some resolution of this issue in future release

應該使用"weblogic.http.client.defaultConnectTimeout"屬性
在weblogic9的weblogic.net.http.HttpURLConnection類里找到如下的代碼
defaultConnectTimeout = Integer.getInteger("weblogic.http.client.defaultConnectTimeout", -1).intValue();
而在weblogic8.1 sp4的該類里沒找到,或許sp5就有了(見http://download.oracle.com/docs/cd/E13222_01/wls/docs81///javadocs/weblogic/net/http/HttpURLConnection.html)

? 現在的問題是,對于這種問題可不可以通過超時設定來釋放線程。weblogic中,RJVM(即server之間,可能是admin-to- managed,也可能是managed-to-managed)之間,連接的協議有兩類五種,兩類是http、t3,五種是http、https、 t3、t3s、local。超時設定時協議層面的東西,所以我們這里只討論http和t3。

?????? 對于t3,從上面的trace可以看到,連接的創建從ServerURL.findOrCreateRJVM()開始,這個方法有多種實現,不同的實現使用不同的timeout,客戶端程序可以通過向environment中set一個叫做weblogic.jndi.requestTimeout的變量,如果不做設定,則使用系統默認的DEFAULT_CONNECTION_TIMEOUT,這是個靜態值(0)。而在上面的stacktrace中,我們可以看到,environment是在RemoteChannelServiceImpl中定義的,這個environment對于客戶而言是不可配置的,而weblogic自己的這個env中是不設定requesttimeotu的,也就是,無論哪種方式,connectionTimeout/readTimeout對于t3,都是不可配置的,而且默認是沒有超時的。

??????? 而對于http,HTTPClientJVMConnection在創建HttpURLConnection的時候,會讀取系統環境變量中的如下兩個變量,
[b]weblogic.http.client.defaultReadTimeout[/b]
[b]weblogic.http.client.defaultConnectTimeout[/b]
??????? 如果沒有設定,這兩個變量的默認值均為-1,即不做timeout。如果我們作了設定,這兩個值即讀超時、連接超時都會生效。這兩個值可以用于解決上述的問題。
?? ??? ?weblogic.http.client.defaultReadTimeout
weblogic.http.client.defaultConnectTimeout

哪里可以設置呢?
舉例:
Windows平臺:
set JAVA_OPTIONS=-Dweblogic.http.client.defaultReadTimeout=30 -Dweblogic.http.client.defaultConnectTimeout=30 %JAVA_OPTIONS%
UNIX/Linux平臺:
JAVA_OPTIONS="-Dweblogic.http.client.defaultReadTimeout=30 -Dweblogic.http.client.defaultConnectTimeout=30 $JAVA_OPTIONS"
export JAVA_OPTIONS



leekiang 2010-04-14 16:59 發表評論
]]>
nginx筆記http://www.tkk7.com/leekiang/archive/2010/03/29/316779.htmlleekiangleekiangSun, 28 Mar 2010 17:13:00 GMThttp://www.tkk7.com/leekiang/archive/2010/03/29/316779.htmlhttp://www.tkk7.com/leekiang/comments/316779.htmlhttp://www.tkk7.com/leekiang/archive/2010/03/29/316779.html#Feedback0http://www.tkk7.com/leekiang/comments/commentRss/316779.htmlhttp://www.tkk7.com/leekiang/services/trackbacks/316779.htmlC10K問題探討
http://www.kegel.com/c10k.html


Host Websites with nginx on CentOS 5


leekiang 2010-03-29 01:13 發表評論
]]>
Tomcat的啟動http://www.tkk7.com/leekiang/archive/2009/07/30/289107.htmlleekiangleekiangThu, 30 Jul 2009 05:57:00 GMThttp://www.tkk7.com/leekiang/archive/2009/07/30/289107.htmlhttp://www.tkk7.com/leekiang/comments/289107.htmlhttp://www.tkk7.com/leekiang/archive/2009/07/30/289107.html#Feedback0http://www.tkk7.com/leekiang/comments/commentRss/289107.htmlhttp://www.tkk7.com/leekiang/services/trackbacks/289107.html 這個startup.bat腳本就是提供給使用者用來修改的,我們可以在其中設置JAVA_HOMECATALINA_HOME等環境變量,但我們并不需要深入到較為復雜的catalina.bat腳本中,這正是startup.bat腳本的真正用意所在。我們知道,軟件設計模式中有一個重要的原則就是開閉原則,即我們可以允許別人擴展我們的程序,但在程序發布后,我們拒絕任何修改,因為修改會產生新的Bug,使得我們已經Bug-free的程序又要重新測試。開閉原則是面向對象世界中的一個非常重要的原則,我們可以把這個原則從Java類擴展至源代碼級別。startup腳本就是要求用戶不要修改catalina.bat腳本,這是符合軟件設計思想的。我們如果想要徹底貫徹這個重要的軟件設計原則,可以寫一個新腳本tomcat.bat,腳本內容大致如下:

set JAVA_HOME=C:\Program Files\Java\jdk1.5.0_09
set CATALINA_HOME=C:\carl\it\tomcat_research\jakarta-tomcat-5.0.28
call %CATALINA_HOME%\bin\startup.bat

這個tomcat.bat文件可以存放在任何目錄并能執行,并且不需要修改tomcat自帶的任何腳本及其它環境變量,這就徹底貫徹了開閉原則。

淺析Tomcat的啟動 http://www.56base.com/blog/u/evian/archives/2008/118.html


leekiang 2009-07-30 13:57 發表評論
]]>
apache服務器http://www.tkk7.com/leekiang/archive/2008/08/06/220515.htmlleekiangleekiangWed, 06 Aug 2008 13:51:00 GMThttp://www.tkk7.com/leekiang/archive/2008/08/06/220515.htmlhttp://www.tkk7.com/leekiang/comments/220515.htmlhttp://www.tkk7.com/leekiang/archive/2008/08/06/220515.html#Feedback0http://www.tkk7.com/leekiang/comments/commentRss/220515.htmlhttp://www.tkk7.com/leekiang/services/trackbacks/220515.html注意:如果windows里已經裝了oracle,則會存在一個8080端口的apache服務,此時安裝apache時不要選那個8080端口的,而是要選80端口的,否則這個新的apache安裝后沒有對應的windows服務。
???? 卸載apache后httpd.conf配置文件還在,重裝apache時會重用這個文件,不會覆蓋。
php以module方式與Apache相結合,使php融入Apache,照先前的方法打開Apache的配置文件,Ln 173,找到這里,添加進如圖所示選中的兩行,第一行“LoadModule php5_module D:/php/php5apache2.dll”是指以module方式加載php,第二行“PHPIniDir "D:/php"”是指明php的配置文件php.ini的位置,是當然,其中的“D:/php”要改成你先前選擇的php解壓縮的目錄
Apache+php+mysql在windows下的安裝與配置圖解


leekiang 2008-08-06 21:51 發表評論
]]>
tomcat筆記http://www.tkk7.com/leekiang/archive/2008/08/01/219432.htmlleekiangleekiangFri, 01 Aug 2008 10:42:00 GMThttp://www.tkk7.com/leekiang/archive/2008/08/01/219432.htmlhttp://www.tkk7.com/leekiang/comments/219432.htmlhttp://www.tkk7.com/leekiang/archive/2008/08/01/219432.html#Feedback0http://www.tkk7.com/leekiang/comments/commentRss/219432.htmlhttp://www.tkk7.com/leekiang/services/trackbacks/219432.htmljavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl
javax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
參見:
http://jefferson.javaeye.com/blog/35239
http://dyfh.spaces.live.com/blog/cns!E99B9675D4683F12!1858.entry
http://chanson.javaeye.com/blog/151007

2,在tomcat后臺的Tomcat Manager里可以遠程發布war,小心被別人利用,得把管理員密碼改掉。
參見走出誤區 巧補Tomcat服務器漏洞


leekiang 2008-08-01 18:42 發表評論
]]>
weblogic性能調優筆記http://www.tkk7.com/leekiang/archive/2008/02/27/182560.htmlleekiangleekiangWed, 27 Feb 2008 13:39:00 GMThttp://www.tkk7.com/leekiang/archive/2008/02/27/182560.htmlhttp://www.tkk7.com/leekiang/comments/182560.htmlhttp://www.tkk7.com/leekiang/archive/2008/02/27/182560.html#Feedback0http://www.tkk7.com/leekiang/comments/commentRss/182560.htmlhttp://www.tkk7.com/leekiang/services/trackbacks/182560.html<2008-2-27 下午09時37分48秒 CST> <Error> <WebLogicServer> <BEA-000337> <ExecuteThread: '14' for queue: 'weblogic.kernel.Default' has been busy for "1,720" seconds working on the request "Http Request: /myapp/test/index.jsp", which is more than the configured time (StuckThreadMaxTime) of "600" seconds.>
2,線程數(Tread Count):指派到weblogic.kernel.Default隊列的線程數。如果你不需要使用超過15個線程(默認),就不必更改這個屬性值。
也可以在mydomain下的config.xml中配置
<ExecuteQueue Name="weblogic.kernel.Default" ThreadCount="50"/>



9,
Bea Weblogic 8.1 SP5 性能優化
weblogic中影響性能的參數總結
發布在weblogic里的程序隨時間越長就越慢
weblogic中影響性能的參數總結
優化WebLogic服務器性能參數
性能調優及UNIX操作
隊列長度一直很高,吞吐量不大,訪問很慢是怎么回事?
Thread Dump 和Java應用診斷
WLS8.15常報socket或連接錯誤,什么原因?
Weblogic服務器性能調優
一個client和server之間的問題
java,weblogic和jdk性能文檔
http://hi.baidu.com/luyi%5F11/blog/item/d32ea497b0776d6e55fb96d5.html
http://hi.baidu.com/amyihohn/blog/item/79fc8d167c96fe51f2de3230.html
http://hi.baidu.com/luyi_11/blog/item/5300f1f0279c0aaca40f52d1.html
http://www.javaeye.com/topic/140849






leekiang 2008-02-27 21:39 發表評論
]]>
weblogic筆記http://www.tkk7.com/leekiang/archive/2008/01/02/172052.htmlleekiangleekiangTue, 01 Jan 2008 20:11:00 GMThttp://www.tkk7.com/leekiang/archive/2008/01/02/172052.htmlhttp://www.tkk7.com/leekiang/comments/172052.htmlhttp://www.tkk7.com/leekiang/archive/2008/01/02/172052.html#Feedback0http://www.tkk7.com/leekiang/comments/commentRss/172052.htmlhttp://www.tkk7.com/leekiang/services/trackbacks/172052.html2, weblogic8,某應用(myapp)以非war包的方式部署時,其編譯后的jsp的類放在以下目錄。
C:\bea\user_projects\domains\mydomain\MISSERVER\.wlnotdelete\extract\MISSERVER__appsdir_myapp_dir_myapp
3,在"IE屬性"設置里"高級"選項卡里,有一項:"顯示友好的HTTP錯誤消息",禁用
這樣錯誤信息就詳細了
4,問題:weblogic9,某應用的jar包更新后,不起作用。
? 解決:在weblogic console里先停止該應用,再刪掉,然后重新配置

5,WebLogic生產模式下啟動時設置自動登錄方法:
在WebLogic啟動腳本相同目錄下創建一個密碼存儲文件boot.properties,文件內容:
username=你的WebLogic的啟動用戶
password=你的WebLogic的啟動密碼
再次啟動WebLogic就不需要密碼了,用戶名和密碼被WebLogic加密后重新保存。

6,org.hibernate.hql.ast. HqlToken 錯誤 weblogic異常
1)、拷貝Hibernate3里帶的包antlr-2.7.5H3.jar到%WL_HOME%\server\lib下
2)、修改% mydomain% \ startWebLogic.cmd :
在set CLASSPATH之前加上下面一句:
set PRE_CLASSPATH=%WL_HOME%\server\lib\antlr-2.7.5H3.jar;
在set CLASSPATH之后加上下面一句:
set CLASSPATH=%PRE_CLASSPATH%;%CLASSPATH%
見http://wangzhen-1104.javaeye.com/blog/221444

7,weblogic8執行response.setCharacterEncoding報錯
weblogic8只支持j2ee1.3,而javax.servlet.http.HttpServletResponse.setCharacterEncoding好像是servlet2.4的,它對應的是j2ee1.4。

8, 如何在WebLogic 8.1.6環境中查找有連接池泄漏的代碼

9,weblogic8里,如果使用連接池,則
rs是ResultSet_oracle_jdbc_driver_OracleResultSetImpl。
rs.getBlob取得的是weblogic.jdbc.wrapper.Blob_oracle_sql_BLOB,而不是oracle.sql.BLOB
?




leekiang 2008-01-02 04:11 發表評論
]]>
tomcat的URIEncoding的作用(轉)http://www.tkk7.com/leekiang/archive/2007/10/17/153685.htmlleekiangleekiangWed, 17 Oct 2007 13:47:00 GMThttp://www.tkk7.com/leekiang/archive/2007/10/17/153685.htmlhttp://www.tkk7.com/leekiang/comments/153685.htmlhttp://www.tkk7.com/leekiang/archive/2007/10/17/153685.html#Feedback0http://www.tkk7.com/leekiang/comments/commentRss/153685.htmlhttp://www.tkk7.com/leekiang/services/trackbacks/153685.html
<Connector port="8080" maxThreads="150" minSpareThreads="25"
maxSpareThreads="75" enableLookups="false" redirectPort="8443"
acceptCount="100" debug="99" connectionTimeout="20000"
disableUploadTimeout="true" URIEncoding="UTF-8"/>

這里指定了get時候的數據編碼。但是,當使用IIS作為webserver轉發servlet/jsp請求給Tomcat時候,這個設置卻失效了。其實原因很簡單:IIS是通過AJP協議,把請求轉發到Tomcat監聽的8009端口上的,所以這里針對8080的設置自然就無效了。正確的方法是進行下面的設置:

<Connector port="8009" enableLookups="false" redirectPort="8443"
debug="0" protocol="AJP/1.3" URIEncoding="UTF-8"/>


leekiang 2007-10-17 21:47 發表評論
]]>
ClientAbortException,Connection reset by peer: socket write error (摘自javaeye)http://www.tkk7.com/leekiang/archive/2007/08/10/135838.htmlleekiangleekiangFri, 10 Aug 2007 06:50:00 GMThttp://www.tkk7.com/leekiang/archive/2007/08/10/135838.htmlhttp://www.tkk7.com/leekiang/comments/135838.htmlhttp://www.tkk7.com/leekiang/archive/2007/08/10/135838.html#Feedback5http://www.tkk7.com/leekiang/comments/commentRss/135838.htmlhttp://www.tkk7.com/leekiang/services/trackbacks/135838.html ? extremetable導出excel,彈出一個下載窗口,這時不點下載而點取消,則報下面的異常:
ClientAbortException?
Caused by: java.net.SocketException: Connection reset by peer: socket write error

查了下TOMCAT的文檔,解釋如下:
Wrap an IOException identifying it as being caused by an abort of a request by a remote client.
在BAIDU和GOOGLE上找了下原因,大概歸結為:
ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error的原因是由于處理http連接時,正在輸出內容時,用戶關閉了IE,會出現一個"ClientAbortException",屬于I/O處理中出現的一個異常,應用服務器應該會捕捉。
Connection reset by peer的原因:
經常出現的Connection reset by peer: 原因可能是多方面的,不過更常見的原因是:
①:服務器的并發連接數超過了其承載量,服務器會將其中一些連接Down掉;
②:客戶關掉了瀏覽器,而服務器還在給客戶端發送數據;
③:瀏覽器端按了Stop
很多人都說是客戶端造成的,沒有辦法控制,是個比較郁悶的問題。

但是,我擔心的是:雖然前臺沒有任何出錯的跡象,但是后臺會記錄這個異常,日志也會瘋狂爆滿,時間長了,肯定會DOWN掉的,還沒找到好的解決辦法
resin有一個參數ignore-client-disconnect
tomcat似乎沒有


經常出現的Connection reset by peer: 原因可能是多方面的,不過更常見的原因是:①:服務器的并發連接數超過了其承載量,服務器會將其中一些連接Down掉;②:客戶關掉了瀏覽器,而服務器還 在給客戶端發送數據;③:瀏覽器端按了Stop

[10054] Connection reset by peer
  Connection reset by peer is a tough one because it can be caused by so many things. In all cases, the server determines that the socket is no longer good and closes it from its side.
  Read Error
  Scenario: Mary couldn't make out what Joe was saying anymore, so she hung up rather than lose his messages (data).
  A read error occurs when a server cannot successfully read from a user's client. Servers gather information from the client by text, setup, and other items.When the server receives an error when reading from a client, it then disconnects the user, resulting in a read error quit message.
  Write Error
  Scenario: Mary was trying to talk to Joe but didn't think she was getting through, so she hung rather than lose his messages (data).
  A write error occurs when a server cannot successfully write to a user's client. When the server receives information, it usually responds with information of its own. When the server receives an error when writing to a client, it then disconnects the user, resulting in a write error quit message similar to the read error format.
  Ping Timeout Error
  Scenario: Mary, having been raised in a household with too many kids and always craving attention, keeps asking to make sure that Joe is still on the line and listening. If he doesn't reply fast enough to suit her, she hangs up.
   Servers automatically ping users at a preset time. The reason for this is to ensure the client is still connected to the server. When you see "PING? PONG!" results in your status window, it means the server has pinged your client, and it has responded back with a pong to ensure the server that you are still connected. When this does not happen and you disconnect without the server's knowledge, the server will automatically disconnect the user when it does not receive a response, resulting in a ping timeout. Ping timeouts occur to EVERYONE.
  Broken pipe Error
   Scenario: Mary had picked up a sticky note with a message she needed to relay to Joe, but somehow between her hand and her mouth, the message got misplaced. Mary was trying to talk to Joe but didn't think she was getting through, so she hung up rather than lose his messages (data).
   A broken pipe error occurs when the server knows it has a message but can't seem to use its internal data link to get the data out to the socket.
  Miscellaneous
  Scenario: Lots of other reasons; perhaps the operator broke in and gave Mary a message that made her doubt the validity of the call so she hung up



leekiang 2007-08-10 14:50 發表評論
]]>
tomcat與jboss(摘自javaeye)http://www.tkk7.com/leekiang/archive/2007/07/26/132595.htmlleekiangleekiangThu, 26 Jul 2007 09:36:00 GMThttp://www.tkk7.com/leekiang/archive/2007/07/26/132595.htmlhttp://www.tkk7.com/leekiang/comments/132595.htmlhttp://www.tkk7.com/leekiang/archive/2007/07/26/132595.html#Feedback0http://www.tkk7.com/leekiang/comments/commentRss/132595.htmlhttp://www.tkk7.com/leekiang/services/trackbacks/132595.html????? jboss默認實現了APR,性能要好不少了吧?還有安全框架、數據庫連接池、JTA等方面。


JBoss,Geronimo還是Tomcat?
Four open source Java application servers compared


leekiang 2007-07-26 17:36 發表評論
]]>
主站蜘蛛池模板: 久久精品亚洲一区二区| 亚洲乱妇熟女爽到高潮的片| 日本亚洲免费无线码| 亚洲av日韩aⅴ无码色老头| 国产亚洲成归v人片在线观看 | 亚洲AV日韩AV永久无码免下载| 四虎永久在线观看免费网站网址 | 在线观看特色大片免费网站| 亚洲三级在线播放| 亚洲欧洲一区二区三区| 日本最新免费网站| 中文字幕视频免费在线观看| 国产精品亚洲综合久久| 亚洲精品成人片在线播放| 好爽…又高潮了免费毛片| 免费视频精品一区二区三区| 国产成人精品亚洲| 亚洲女人初试黑人巨高清| 国产亚洲老熟女视频| 免费观看的a级毛片的网站| 免费国产污网站在线观看15| 一级做a爰黑人又硬又粗免费看51社区国产精品视| 亚洲视频免费在线观看| 亚洲无码高清在线观看| 成人在线视频免费| 亚欧免费视频一区二区三区| 国产特黄一级一片免费| 老司机亚洲精品影院在线观看| 亚洲视频小说图片| 亚洲国产精品无码专区| 亚洲精品A在线观看| 免费高清av一区二区三区| 国产高清免费视频| 久久午夜伦鲁片免费无码| GOGOGO高清免费看韩国| 免费看黄网站在线看| 亚洲AV成人片无码网站| 美女视频黄免费亚洲| 亚洲国产成人久久77| 亚洲综合在线观看视频| 亚洲高清在线视频|