JNA据说比jni简单很多,这里有一篇介绍,用法简单、但性能比jni有所下降(基于jni):
http://blog.csdn.net/shendl/article/details/3589676/
es中用得更简单:
package org.elasticsearch.common.jna;
import com.sun.jna.Native;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
/**
*
*/
public class CLibrary {
private static ESLogger logger = Loggers.getLogger(CLibrary.class);
public static final int MCL_CURRENT = 1;
public static final int MCL_FUTURE = 2;
public static final int ENOMEM = 12;
static {
try {
Native.register("c");
} catch (NoClassDefFoundError e) {
logger.warn("JNA not found. native methods (mlockall) will be disabled.");
} catch (UnsatisfiedLinkError e) {
logger.warn("unable to link C library. native methods (mlockall) will be disabled.");
}
}
public static native int mlockall(int flags);
public static native int munlockall();
private CLibrary() {
}
}