作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
通过 Java source code我们有那个
// variable not written or updated anywhere on this class
private volatile int threadStatus = 0;
public State getState() {
// get current thread state
return sun.misc.VM.toThreadState(threadStatus);
}
threadStatus
如何以及在哪里更新?
我们的想法是最终尝试使用 AOP 围绕更新方法进行编织,并在 threadStatus
更改时进行回调。
最佳答案
在文件hotspot/src/share/vm/classfile/javaClasses.cpp
中的OpenJDK源代码中,您可以看到以下代码:
// Write the thread status value to threadStatus field in java.lang.Thread java class.
void java_lang_Thread::set_thread_status(oop java_thread,
java_lang_Thread::ThreadStatus status) {
// The threadStatus is only present starting in 1.5
if (_thread_status_offset > 0) {
java_thread->int_field_put(_thread_status_offset, status);
}
}
看起来状态是在 native 代码中管理的。这意味着您无法从 Java 代码中拦截它的更改。
关于java.lang.Thread - threadStatus 从何而来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53406078/
关闭。这个问题需要 details or clarity 。目前不接受答案。 想要改进这个问题?通过 editing this post 添加详细信息并澄清问题。 已关闭 9 年前。 奥 git _a
通过 Java source code我们有那个 // variable not written or updated anywhere on this class private volatile
我是一名优秀的程序员,十分优秀!