私はapache httpクライアントを使用して、パイプでストリームを使用してコンテンツを書き込む、いくつかの投稿要求をターゲットサーバに実行しています。ですから、基本的には、あるスレッドのHTTPクライアントはPipedInputStream
から読み込み、別のスレッドからはPipedOutputStream
のコンテンツを書きます。Java PipedInputStreamスレッドは、ロックを保持している他のスレッドがないBLOCKED状態ですか?
毎回、スレッドダンプを取得していて、java.io.PipedInputStream.read()
メソッドがブロックされているのを確認して、wait(1000)
行を実行しています。 BLOCKED状態は、1000 ms
が経過した後に読み取りスレッドがロックを取得するのを待機していることを意味します。しかし、私が理解していないのは、スレッドダンプでロックを保持する書き込みスレッドを見ることができない理由です。何が欠けていて、スレッドをブロックしないようにするにはどうすればいいですか?
Thread 7912: (state = BLOCKED)
- java.lang.Object.wait(long) @bci=0 (Compiled frame; information may be imprecise)
- java.io.PipedInputStream.read() @bci=142, line=326 (Compiled frame)
- java.io.PipedInputStream.read(byte[], int, int) @bci=43, line=377 (Compiled frame)
- org.apache.http.entity.InputStreamEntity.writeTo(java.io.OutputStream) @bci=75, line=140 (Compiled frame)
- org.apache.http.impl.execchain.RequestEntityProxy.writeTo(java.io.OutputStream) @bci=10, line=123 (Compiled frame)
- org.apache.http.impl.DefaultBHttpClientConnection.sendRequestEntity(org.apache.http.HttpEntityEnclosingRequest) @bci=31, line=156 (Compiled frame)
- org.apache.http.impl.conn.CPoolProxy.sendRequestEntity(org.apache.http.HttpEntityEnclosingRequest) @bci=5, line=162 (Compiled frame)
- org.apache.http.protocol.HttpRequestExecutor.doSendRequest(org.apache.http.HttpRequest, org.apache.http.HttpClientConnection, org.apache.http.protocol.HttpContext) @bci=223, line=238 (Compiled frame)
- org.apache.http.protocol.HttpRequestExecutor.execute(org.apache.http.HttpRequest, org.apache.http.HttpClientConnection, org.apache.http.protocol.HttpContext) @bci=25, line=123 (Compiled frame)
- org.apache.http.impl.execchain.MainClientExec.execute(org.apache.http.conn.routing.HttpRoute, org.apache.http.client.methods.HttpRequestWrapper, org.apache.http.client.protocol.HttpClientContext, org.apache.http.client.methods.HttpExecutionAware) @bci=714, line=271 (Compiled frame)
- org.apache.http.impl.execchain.ProtocolExec.execute(org.apache.http.conn.routing.HttpRoute, org.apache.http.client.methods.HttpRequestWrapper, org.apache.http.client.protocol.HttpClientContext, org.apache.http.client.methods.HttpExecutionAware) @bci=447, line=184 (Compiled frame)
- org.apache.http.impl.execchain.RetryExec.execute(org.apache.http.conn.routing.HttpRoute, org.apache.http.client.methods.HttpRequestWrapper, org.apache.http.client.protocol.HttpClientContext, org.apache.http.client.methods.HttpExecutionAware) @bci=39, line=88 (Compiled frame)
- org.apache.http.impl.client.InternalHttpClient.doExecute(org.apache.http.HttpHost, org.apache.http.HttpRequest, org.apache.http.protocol.HttpContext) @bci=168, line=184 (Compiled frame)
- org.apache.http.impl.client.CloseableHttpClient.execute(org.apache.http.client.methods.HttpUriRequest, org.apache.http.protocol.HttpContext) @bci=14, line=82 (Compiled frame)
- org.apache.http.impl.client.CloseableHttpClient.execute(org.apache.http.client.methods.HttpUriRequest) @bci=6, line=107 (Compiled frame)
データがない場合、読み取りスレッドは読み取りメソッド内でwhileループを実行しているか、そのループ内からwait(long)を実行中であるため、 'RUNNABLE'または' TIMED_WAITING'状態になります。 'BLOCKED'状態にあるということは、他のスレッドがそのロックを持っていることを意味しますが、スレッドダンプにそのような書き込みスレッドはありません。 –
出力ストリームは「データを取得」しません。また、inputStreamにデータがある間は読み書き待ちではありません。それはどういう意味ですか、間違っているのか、この答えはわかりにくく、分かりやすいところでは間違っています。 – EJP