简体   繁体   English

使用 JNA 在 JAVA 中加载动态库有限制吗?

[英]Is there a limit in loading dynamic libraries in JAVA using JNA?

Good morning,早上好,

We are executing the following code and we are reaching an error message when loading a certain number of dlls:我们正在执行以下代码,并且在加载一定数量的 dll 时出现错误消息:

File file = new File("C:\\Users\\jevora\\Downloads\\dng_tests\\dllsCopies");
    file.mkdirs();
    for (int i = 1; i < 10000; i++) {
        String filename = "heatedTankCvode" + i + ".dll";
        Files.copy(new File("C:\\Users\\jevora\\Downloads\\dng_tests\\heatedTankCvode.dll").toPath(),
                new File(file, filename).toPath(), StandardCopyOption.REPLACE_EXISTING);
        NativeLibrary.getInstance(new File(file, filename).getAbsolutePath());
        System.out.println("Loaded: " + filename);
    }

As you can see here, we want to load 10,000 dlls using JNA.正如您在此处看到的,我们希望使用 JNA 加载 10,000 个 dll。 However,in the following log, the process stops at loading the instance 1,051:但是,在以下日志中,进程在加载实例 1,051 时停止:

Loaded: heatedTankCvode1048.dll
Loaded: heatedTankCvode1049.dll
Loaded: heatedTankCvode1050.dll
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'C:\Users\jevora\Downloads\dng_tests\dllsCopies\heatedTankCvode1051.dll': Native library (win32-x86-64/C:\Users\jevora\Downloads\dng_tests\dllsCopies\heatedTankCvode1051.dll)

About the code, first we copy the dll in a new location with a different name and, then, we try to load it.关于代码,首先我们将 dll 复制到具有不同名称的新位置,然后尝试加载它。 We wonder if there is a limitation to the amount of dlls that can be loaded.我们想知道可以加载的 dll 数量是否有限制。 Is there a limitation?有限制吗? can we overcome it?我们能克服它吗?

Thanks in advance提前致谢

EDIT: I've tried with several memory configurations and it always stop in the 1051 instance编辑:我尝试了几种内存配置,但它总是在 1051 实例中停止

I think that the cause might be explained by this old Microsoft Forum post:我认为原因可能可以通过这篇旧的 Microsoft 论坛帖子来解释:

It appears that each DLL that you are loading is consuming a TLS (thread local storage) slot .您正在加载的每个 DLL 似乎都在消耗TLS(线程本地存储)槽 There is a per process limit of 1088 on the number of TLS slots.每个进程的 TLS 插槽数量限制为 1088。 From all that I have read, the limit is hard ... and there is no way to increase it.从我读过的所有内容来看,限制很难......而且没有办法增加它。

From what I have read, a DLL doesn't have to use TLS, so you should investigate if you can change the way that your DLLs are created so that they don't do this.从我已阅读,一个DLL没有使用TLS,所以你应该调查,如果你可以改变你的DLL文件被创建,使他们不这样做的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM