JAVA-JNA:调用dll,运行几次,然后Invalid memory access

问题描述 投票:0回答:1

java通过jna调用delphi创建的dll可以运行几次,然后会报错。是类型不对,还是dll内存有问题什么的?

爪哇:

String invoke(String fileName, float a, float b, float c, float d,
                 float e, float f, float g, float h, float i,
                 float j, String k);

delphi->dll:

function invoke(filename: PAnsiChar; a, b, c, d, e, f, g, h, i, j: single; k: PAnsiChar): PAnsiChar; stdcall;

===================================9th time, call DLL===================================
===================================10th time, call DLLL===================================
2023-03-10 10:25:56.417 ERROR 12592 --- [-nio-94-exec-10] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.Error: Invalid memory access] with root cause

java.lang.Error: Invalid memory access
    at com.sun.jna.Native.invokePointer(Native Method) ~[jna-5.5.0.jar:5.5.0 (b0)]
    at com.sun.jna.Function.invokePointer(Function.java:497) ~[jna-5.5.0.jar:5.5.0 (b0)]
    at com.sun.jna.Function.invokeString(Function.java:660) ~[jna-5.5.0.jar:5.5.0 (b0)]
    at com.sun.jna.Function.invoke(Function.java:434) ~[jna-5.5.0.jar:5.5.0 (b0)]
    at com.sun.jna.Function.invoke(Function.java:361) ~[jna-5.5.0.jar:5.5.0 (b0)]
    at com.sun.jna.Library$Handler.invoke(Library.java:265) ~[jna-5.5.0.jar:5.5.0 (b0)]
    at com.sun.proxy.$Proxy98.invoke(Unknown Source) ~[na:na]
    at com.xxx.xxx.dll.impl.DllImpl.invoke(DllImpl.java:40) ~[classes/:na]
    at com.xxx.xxx.dll.impl.DllImpl$$FastClassBySpringCGLIB$$92dce636.invoke(<generated>) ~[classes/:na]
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.1.12.RELEASE.jar:5.1.12.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:750) ~[spring-aop-5.1.12.RELEASE.jar:5.1.12.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.1.12.RELEASE.jar:5.1.12.RELEASE]
    at org.springframework.validation.beanvalidation.MethodValidationInterceptor.invoke(MethodValidationInterceptor.java:120) ~[spring-context-5.1.12.RELEASE.jar:5.1.12.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.12.RELEASE.jar:5.1.12.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689) ~[spring-aop-5.1.12.RELEASE.jar:5.1.12.RELEASE]
    at com.xxx.xxx.dll.impl.DllImpl$$EnhancerBySpringCGLIB$$c67e343.invoke(<generated>) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_341]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_341]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_341]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_341]

从jvm中的内存中没有发现异常,也没有看到溢出

不知道是不是我查的数据有问题,还请大家给个答复。谢谢

java delphi dll jna
1个回答
0
投票

公共类 DllImpl 扩展 DllManage 实现 DllProvider {

public static AtomicInteger count = new AtomicInteger(0);
@Override
public synchronized ResponseEntity<String> invoke(String fileName, float a, float b,
                                                  float c, float d, float e, float f, float g, float h, float i, float j, String k) {
    System.setProperty("jna.encoding", "GBK");
    count.getAndIncrement();
    String result = null;
    System.out.println("==================================="+count+"th time, call DLL===================================");
    try {
        result = DLL.MTAWDll.invoke(fileName,
                a,b,c,d,e,f,g,h,i,j,
                k);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    System.gc();
    return new ResponseEntity<>(result, HttpStatus.OK);

}

}

这是我调用的方法。是不是我主动唤醒gc造成的

© www.soinside.com 2019 - 2024. All rights reserved.