I am implementing a function that requires the transfer of dynamically generated types (in binary representation serialized using Kryo) between multiple JVM instances (over the network). To correctly decide which types are loaded and what I do not use, a custom system class loader (passed as a java parameter -Djava.system.class.loader) that is used by other dynamically created class loaders as a parent. This custom system class loader is aware of its children, and if it cannot find the class, these derived class loaders can be set if any (this refers to the standard hierarchical structure of class loaders).
These dynamically generated types are passed and loaded between different JVMs perfectly. The problem occurs when I try to deserialize an instance of some type (the corresponding class is loaded from disk and is identical for all JMVs), which refers to one of the dynamically generated types - ClassNotFoundException is thrown by an instance of Kryo, which tries readClassby the name of the dynamically generated type.
Inside the method, readClassthere is a call Class.forNamethat, in turn, does not use the specified user-defined class loader (which knows all dynamically generated types) and instead uses an instance of sun.misc.Launcher $ AppClassLoader.
Is it possible to specify a custom system class loader so that all classes are loaded with it to avoid the described problem?
Update
, ClassLoader.getSystemClassLoader() . , Kryo . .