Java threads: interpreting thread states of a running JVM

偶尔善良 提交于 2019-12-03 17:36:56

This level of output doesn't provide enough information to make such statements.

As an example, consider the BLOCKED state: there are many things that can cause a thread to be blocked. Two of them are waiting for data to come from a client, and waiting for data to come back from a database. In the first case, your application is idle, in the second it's overloaded.

Edit: not having looked at the output from jstack, I suppose that these two conditions could also be represented as IN_NATIVE. However, the same comment holds: you don't know what they're doing, so you can't make any statements about the application as a whole.

kdgregory is correct that thread state won't necessarily reveal what you want by itself. However, jstack should also give you stack traces, letting you see exactly where the threads are in your program (assuming it's not obfuscated or something). A BLOCKED thread whose trace contains a call to InputStream.read(), for example, should be fairly obvious.

I'd say what's interesting in general when looking at thread states or indeed profiling data in general is to be able to ask yourself "Did I expect this to be the case?" If you have no opinion on whether the data you're getting is bad/good/expected/unexpected, then it's difficult to do much about it.

With thread states, I think this is more interesting to look at the behaviour of individual threads and then ask yourself "did I expect that thread to be in that state/waiting for that lock for quite so long?" And just knowing that a given thread is blocked/waiting etc per se isn't so interesting as knowing WHAT it was blocked/waiting for.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!