由不同的类加载器加载的相同本机库 [英] Same native library loaded by different class loader

查看:164
本文介绍了由不同的类加载器加载的相同本机库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下场景:

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

I have two java classes, loaded using different system class loaders. I have a native library that has a queue implemented. Both the classes will load the same library, and add elements to the queue. Is it possible? If so, will the native library implementation be shared across the two classes.?

推荐答案

根据 JNI规范是不可能的。


在JDK中,每个类加载器都管理自己的一组本机库。 无法将相同的JNI本机库加载到多个类加载器中。这样做会导致抛出 UnsatisfiedLinkError 。例如, System.loadLibrary 在用于将本机库加载到两个类加载器时抛出 UnsatisfiedLinkError

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.

这篇关于由不同的类加载器加载的相同本机库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆