gpt4 book ai didi

java - 由不同类加载器加载的相同 native 库

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:28:51 26 4
gpt4 key购买 nike

请考虑以下场景:

我有两个 java 类,使用不同的系统类加载器加载。我有一个实现了队列的 native 库。这两个类将加载相同的库,并将元素添加到队列中。是否可以?如果是这样, native 库实现是否会在两个类之间共享?

最佳答案

根据JNI Specification这是不可能的。

In the JDK, each class loader manages its own set of native libraries. The same JNI native library cannot be loaded into more than one class loader. Doing so causes UnsatisfiedLinkError to be thrown. For example, System.loadLibrary throws an UnsatisfiedLinkError when used to load a native library into two class loaders.

关于java - 由不同类加载器加载的相同 native 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16189217/

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