2017-07-28 10 views
3

不審なスレッドダンプをコピーしました。 同じ呼び出しで、java.net.SocketInputStream.socketRead0() コールでIN_NATIVE状態のスレッドが173個、BLOCKED状態のスレッドが30個あります。
BLOCKED状態はCPUを消費しませんが、IO上で待機していると思います。JavaスレッドのダンプCPUまたはIOだけ待ちますか?

IN_NATIVE状態のスレッドはどうですか?彼らはCPUを消費するのですか? 私は同じ呼び出しsocketRead0()のスレッド状態がどう違うのですか?

173 threads 
Thread 40283 - threadId:Thread 40283 - state:IN_NATIVE 
stackTrace: 
java.net.SocketInputStream.socketRead0(java.io.FileDescriptor, byte[], int, int, int) @bci=0 (Compiled frame; information may be imprecise) 
java.net.SocketInputStream.read(byte[], int, int, int) @bci=87, line=152 (Compiled frame) 
java.net.SocketInputStream.read(byte[], int, int) @bci=11, line=122 (Compiled frame) 
com.sun.mail.util.TraceInputStream.read(byte[], int, int) @bci=7, line=110 (Compiled frame) 
java.io.BufferedInputStream.fill() @bci=175, line=235 (Compiled frame) 
java.io.BufferedInputStream.read() @bci=12, line=254 (Compiled frame) 
com.sun.mail.util.LineInputStream.readLine() @bci=33, line=88 (Compiled frame) 
com.sun.mail.smtp.SMTPTransport.readServerResponse() @bci=43, line=1589 (Compiled frame) 
com.sun.mail.smtp.SMTPTransport.openServer(java.lang.String, int) @bci=117, line=1369 (Compiled frame) 
com.sun.mail.smtp.SMTPTransport.protocolConnect(java.lang.String, int, java.lang.String, java.lang.String) @bci=270, line=412 (Compiled frame) 
javax.mail.Service.connect(java.lang.String, int, java.lang.String, java.lang.String) @bci=380, line=288 (Compiled frame) 
com.healthies.push.injectors.mailsenders.DefaultMailSender.sendMessage(com.healthies.push.messages.EmailMessage, javax.mail.internet.MimeMessage) @bci=28, line=63 (Compiled frame) 
com.healthies.push.injectors.SMTPMessageInjector.sendMessage(com.healthies.push.injectors.mailsenders.MailSender, com.healthies.push.messages.EmailMessage, javax.mail.internet.MimeMessage) @bci=55, line=140 (Compiled frame) 
com.healthies.push.injectors.SMTPMessageInjector.inject(com.healthies.push.messages.EmailMessage) @bci=210, line=117 (Compiled frame) 
com.healthies.push.injectors.SMTPMessageInjector.inject(com.healthies.push.messages.Message) @bci=5, line=35 (Compiled frame) 
com.healthies.push.injectors.EmailInjectorPool$1.run() @bci=85, line=40 (Compiled frame) 
java.util.concurrent.Executors$RunnableAdapter.call() @bci=4, line=471 (Compiled frame) 
java.util.concurrent.FutureTask.run() @bci=42, line=262 (Compiled frame) 
java.util.concurrent.ThreadPoolExecutor.runWorker(java.util.concurrent.ThreadPoolExecutor$Worker) @bci=95, line=1145 (Compiled frame) 
java.util.concurrent.ThreadPoolExecutor$Worker.run() @bci=5, line=615 (Interpreted frame) 
java.lang.Thread.run() @bci=11, line=745 (Interpreted frame) 
-------------------------------------------------------------------- 
30 threads 
Thread 40276 - threadId:Thread 40276 - state:BLOCKED 
stackTrace: 
java.net.SocketInputStream.socketRead0(java.io.FileDescriptor, byte[], int, int, int) @bci=0 (Compiled frame; information may be imprecise) 
java.net.SocketInputStream.read(byte[], int, int, int) @bci=87, line=152 (Compiled frame) 
java.net.SocketInputStream.read(byte[], int, int) @bci=11, line=122 (Compiled frame) 
com.sun.mail.util.TraceInputStream.read(byte[], int, int) @bci=7, line=110 (Compiled frame) 
java.io.BufferedInputStream.fill() @bci=175, line=235 (Compiled frame) 
java.io.BufferedInputStream.read() @bci=12, line=254 (Compiled frame) 
com.sun.mail.util.LineInputStream.readLine() @bci=33, line=88 (Compiled frame) 
com.sun.mail.smtp.SMTPTransport.readServerResponse() @bci=43, line=1589 (Compiled frame) 
com.sun.mail.smtp.SMTPTransport.issueSendCommand(java.lang.String, int) @bci=6, line=1494 (Compiled frame) 
com.sun.mail.smtp.SMTPTransport.finishData() @bci=34, line=1321 (Compiled frame) 
com.sun.mail.smtp.SMTPTransport.sendMessage(javax.mail.Message, javax.mail.Address[]) @bci=281, line=637 (Compiled frame) 
com.healthies.push.injectors.mailsenders.DefaultMailSender.sendMessage(com.healthies.push.messages.EmailMessage, javax.mail.internet.MimeMessage) @bci=37, line=64 (Compiled frame) 
com.healthies.push.injectors.SMTPMessageInjector.sendMessage(com.healthies.push.injectors.mailsenders.MailSender, com.healthies.push.messages.EmailMessage, javax.mail.internet.MimeMessage) @bci=55, line=140 (Compiled frame) 
com.healthies.push.injectors.SMTPMessageInjector.inject(com.healthies.push.messages.EmailMessage) @bci=210, line=117 (Compiled frame) 
com.healthies.push.injectors.SMTPMessageInjector.inject(com.healthies.push.messages.Message) @bci=5, line=35 (Compiled frame) 
com.healthies.push.injectors.EmailInjectorPool$1.run() @bci=85, line=40 (Compiled frame) 
java.util.concurrent.Executors$RunnableAdapter.call() @bci=4, line=471 (Compiled frame) 
java.util.concurrent.FutureTask.run() @bci=42, line=262 (Compiled frame) 
java.util.concurrent.ThreadPoolExecutor.runWorker(java.util.concurrent.ThreadPoolExecutor$Worker) @bci=95, line=1145 (Compiled frame) 
java.util.concurrent.ThreadPoolExecutor$Worker.run() @bci=5, line=615 (Interpreted frame) 
java.lang.Thread.run() @bci=11, line=745 (Interpreted frame) 
+0

ソケット読み込みはスピン(非ブロッキングモードで何もしない場合)またはスレッドをブロックすることによってCPU時間を焼くことができますが、jstackはwhihを伝えません。 – the8472

答えて

1

通常、BLOCKED状態の非同期ネイティブメソッドを実行するスレッドは表示されません。しかし、このダンプは強制モード(jstack -F)で得られますが、works differentlyです。

JVMがsafepoint operationをリクエストしたようです。 Javaコードを実行するすべてのスレッドは、safepointで停止する必要がありますが、ネイティブメソッドは引き続き実行されます。ネイティブメソッドが復帰するたびに、Safepoint操作が進行中であるかどうかをチェックし、そうである場合、は、VM操作が完了するまで現在のスレッドをブロックします。

だから、あなたのケースでBLOCKED状態で

  • スレッドがすでにネイティブコールを完了したとメソッドからの戻りでセーフポイント動作の終了を待っています。
  • IN_NATIVE州のスレッドはまだソケット読み取りでブロックされたのネイティブコールを実行しています。それはIN_NATIVE状態でスレッドを表示します両方のケースで -

JVMは、実際にCPUを消費ネイティブメソッドからのシステムコールでブロックされたネイティブメソッドを区別するための手段を持ちません。これらのスレッドがビジーであるかどうかは、スレッド・ダンプから判断することはできません。

ネイティブメソッドがCPUを消費するかどうかを確認するには、top,perfまたはnative code aware profilerのようなユーティリティが必要です。

関連する問題