Skip to content

Commit dff4636

Browse files
committed
FFM : add setLoadLibrary(boolean)
1 parent be16b05 commit dff4636

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/javaforce/ffm/FFM.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ public static FFM getInstance() {
2828
return instance;
2929
}
3030

31-
/** Enabled FFM native inter-ops.
31+
/** Enabled FFM native inter-ops (default = true)
3232
*/
3333
private static boolean enabled = true;
3434

3535
/** Use JNI to pin arrays. */
3636
private static boolean jni_pinning = true;
3737

38+
/** Load JF native library to load JNI methods. */
39+
private static boolean jni_load = false;
40+
3841
/** Returns FFM enabled state. */
3942
public static boolean enabled() {
4043
if (!enabled) {
@@ -74,6 +77,16 @@ public static void disable() {
7477
}
7578
}
7679

80+
/** Set wether to load the JF native library to find JNI methods.
81+
* Default = false
82+
*
83+
* For Tomcat edit conf/server.xml and add to the <server> section:
84+
* <Listener className="org.apache.catalina.core.JniLifecycleListener" libraryPath="c:\programdata\javaforce\jfnative64.dll" />
85+
*/
86+
public static void setLoadLibrary(boolean state) {
87+
jni_load = state;
88+
}
89+
7790
private static String getLibrary() {
7891
if (JF.isWindows()) {
7992
return System.getenv("ProgramData") + "/JavaForce/jfnative64.dll";
@@ -112,7 +125,9 @@ private static void setupLinker() {
112125
//symbol lookup from supplied shared library
113126
arena = Arena.ofAuto(); //freed by gc (which will also close the library at that time)
114127
lookup = SymbolLookup.libraryLookup(lib, arena);
115-
try {System.load(lib);} catch (Throwable t) {JFLog.log(t);} //load JNI methods
128+
if (jni_load) {
129+
try {System.load(lib);} catch (Throwable t) {JFLog.log(t);} //load JNI methods
130+
}
116131
} else {
117132
if (debug) JFLog.log("Loading FFM from executable");
118133
//symbol lookup from executable of this JVM (JavaForce native loader)

0 commit comments

Comments
 (0)