gpt4 book ai didi

java - 在一个线程上初始化的jmethodID可以在另一个线程中使用吗?

转载 作者:行者123 更新时间:2023-12-01 15:21:09 25 4
gpt4 key购买 nike

我们可以在另一个线程中使用在一个线程上初始化的jmethodID吗?我问这个问题是因为当我运行 jni 程序时,我的 jvm 崩溃了,其中我在一个线程上初始化了 jmethodID 并在另一个线程中使用它。我在想这是否可以成为一个原因。

我通过在顶部声明将 jmethodID 保留为全局变量。然后在其中一个调用中我初始化它,并在后续调用中尝试重用它。

最佳答案

引自JNI Specification :

A field or method ID does not prevent the VM from unloading the class from which the ID has been derived. After the class is unloaded, the method or field ID becomes invalid. The native code, therefore, must make sure to:

keep a live reference to the underlying class, or

recompute the method or field ID

if it intends to use a method or field ID for an extended period of time.

关于java - 在一个线程上初始化的jmethodID可以在另一个线程中使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10909468/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com