帮忙看一下java网络编程死锁的情况!
"Thread-14" prio=10 tid=0x00007f09d4024000 nid=0x6021 runnable [0x00007f0a15e68000]java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
- locked <0x000000009a12af98> (a java.io.BufferedInputStream)
at sun.net.www.http.ChunkedInputStream.fastRead(ChunkedInputStream.java:221)
at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:662)
- locked <0x000000009a12afc0> (a sun.net.www.http.ChunkedInputStream)
at java.io.FilterInputStream.read(FilterInputStream.java:116)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2672)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
- locked <0x000000009a12b060> (a java.io.InputStreamReader)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at uestc.dmlab.crawler.main.DownLoadPage.getContentFromUrl(DownLoadPage.java:67)
at uestc.dmlab.crawler.main.UrlDataHanding.dataHanding(UrlDataHanding.java:26)
at uestc.dmlab.crawler.main.UrlDataHanding.run(UrlDataHanding.java:51)
at java.lang.Thread.run(Thread.java:662)
"Thread-13" prio=10 tid=0x00007f09d4022000 nid=0x6020 runnable [0x00007f0a15f69000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
- locked <0x000000008a0bc710> (a java.io.BufferedInputStream)
at sun.net.www.http.ChunkedInputStream.fastRead(ChunkedInputStream.java:221)
at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:662)
- locked <0x000000008a0c8e58> (a sun.net.www.http.ChunkedInputStream)
at java.io.FilterInputStream.read(FilterInputStream.java:116)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2672)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
- locked <0x000000008a0c8f28> (a java.io.InputStreamReader)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at uestc.dmlab.crawler.main.DownLoadPage.getContentFromUrl(DownLoadPage.java:67)
at uestc.dmlab.crawler.main.UrlDataHanding.dataHanding(UrlDataHanding.java:26)
at uestc.dmlab.crawler.main.UrlDataHanding.run(UrlDataHanding.java:48)
at java.lang.Thread.run(Thread.java:662)
"Thread-12" prio=10 tid=0x00007f09d4020000 nid=0x601f runnable [0x00007f0a1606a000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
- locked <0x0000000090902d98> (a java.io.BufferedInputStream)
at sun.net.www.http.ChunkedInputStream.fastRead(ChunkedInputStream.java:221)
at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:662)
- locked <0x0000000090902dc0> (a sun.net.www.http.ChunkedInputStream)
at java.io.FilterInputStream.read(FilterInputStream.java:116)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2672)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
- locked <0x0000000090902e60> (a java.io.InputStreamReader)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at uestc.dmlab.crawler.main.DownLoadPage.getContentFromUrl(DownLoadPage.java:67)
at uestc.dmlab.crawler.main.UrlDataHanding.dataHanding(UrlDataHanding.java:26)
at uestc.dmlab.crawler.main.UrlDataHanding.run(UrlDataHanding.java:51)
at java.lang.Thread.run(Thread.java:662)
这部分的代码
URL path = new URL(gd.url);
String content = "";
HttpURLConnection connection = (HttpURLConnection) path.openConnection();
connection.connect();
InputStream urlStream = connection.getInputStream();
InputStreamReader isr;
if (gd.url.contains("suning") || gd.url.contains("amazon")) {
isr = new InputStreamReader(urlStream, "UTF-8");
} else {
isr = new InputStreamReader(urlStream, "GBK");
}
char[] buf = new char[2048];
int n = 0;
while ((n = isr.read(buf, 0, 2048)) != -1) {
// System.out.println(new String(buf,0,n).toString());
content += new String(buf, 0, n);
}
是什么原因呢 --------------------编程问答-------------------- 没看出来,何以断定是死锁了?
全都停在:
"Thread-13" prio=10 tid=0x00007f09d4022000 nid=0x6020 runnable [0x00007f0a15f69000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
应该是在等待对方的数据而已吧。 --------------------编程问答-------------------- 没看懂~~ 帮顶 --------------------编程问答-------------------- --------------------编程问答--------------------
locked <0x0000000090902dc0> (a sun.net.www.http.ChunkedInputStream)
有几个locked啊 而且一直动不了 --------------------编程问答-------------------- 代码还需要贴全一点吧,特别是加锁的部分
仅上上面的部分,多线程调用你这个方法是不会有问题的,因为每次都产生一个新的连接
补充:Java , Java SE