mirror of
https://github.com/wassname/ray.git
synced 2026-06-28 02:01:24 +08:00
[Java] remove resetLibraryPath (#10671)
This commit is contained in:
@@ -69,8 +69,6 @@ public final class RayNativeRuntime extends AbstractRayRuntime {
|
||||
|
||||
JniUtils.loadLibrary(BinaryFileUtil.CORE_WORKER_JAVA_LIBRARY, true);
|
||||
LOGGER.debug("Native libraries loaded.");
|
||||
// Reset library path at runtime.
|
||||
resetLibraryPath(rayConfig);
|
||||
try {
|
||||
FileUtils.forceMkdir(new File(rayConfig.logDir));
|
||||
} catch (IOException e) {
|
||||
@@ -78,12 +76,6 @@ public final class RayNativeRuntime extends AbstractRayRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
private static void resetLibraryPath(RayConfig rayConfig) {
|
||||
String separator = System.getProperty("path.separator");
|
||||
String libraryPath = String.join(separator, rayConfig.libraryPath);
|
||||
JniUtils.resetLibraryPath(libraryPath);
|
||||
}
|
||||
|
||||
public RayNativeRuntime(RayConfig rayConfig) {
|
||||
super(rayConfig);
|
||||
loadConfigFromGcs(rayConfig);
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package io.ray.runtime.util;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.sun.jna.NativeLibrary;
|
||||
import io.ray.runtime.config.RayConfig;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Set;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -48,38 +46,8 @@ public class JniUtils {
|
||||
}
|
||||
System.load(file.getAbsolutePath());
|
||||
LOGGER.debug("Native library loaded.");
|
||||
resetLibraryPath(file.getAbsolutePath());
|
||||
loadedLibs.add(libraryName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a hack to reset library path at runtime. Please don't use it outside of ray
|
||||
*/
|
||||
public static synchronized void resetLibraryPath(String libPath) {
|
||||
if (Strings.isNullOrEmpty(libPath)) {
|
||||
return;
|
||||
}
|
||||
String path = System.getProperty("java.library.path");
|
||||
String separator = System.getProperty("path.separator");
|
||||
if (Strings.isNullOrEmpty(path)) {
|
||||
path = "";
|
||||
} else {
|
||||
path += separator;
|
||||
}
|
||||
path += String.join(separator, libPath);
|
||||
|
||||
// This is a hack to reset library path at runtime,
|
||||
// see https://stackoverflow.com/questions/15409223/.
|
||||
System.setProperty("java.library.path", path);
|
||||
// Set sys_paths to null so that java.library.path will be re-evaluated next time it is needed.
|
||||
final Field sysPathsField;
|
||||
try {
|
||||
sysPathsField = ClassLoader.class.getDeclaredField("sys_paths");
|
||||
sysPathsField.setAccessible(true);
|
||||
sysPathsField.set(null, null);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
LOGGER.error("Failed to set library path.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user