Login  Register

Re: OSGi: need J3D 1.6 source code for a patch

Posted by JeanPhi on Nov 04, 2013; 1:05pm
URL: https://forum.jogamp.org/OSGi-need-J3D-1-6-source-code-for-a-patch-tp4030430p4030487.html

Each OSGi bundle has its own class loader. Each object related class belongs to a classloader. Hence there are as many class instances per object type as number of bundles which uses it.

J3D initializes itself at class loading. So, in an OSGi world this means one initialization per bundle which makes use of J3D. This is a big problem as Java prevents JNI code from being loaded more than once.

So the cure is to decouple class loading and initialization. At present time I patched VirtualUniverse changing the static {} block to a static method init() {}. Then I created a bundle with a basic blueprint configuration <bean class="...J3DInitializer"/> along with the simple implementation:
public final class J3DInitializer {
 static {
  VirtualUniverse.init();
  // Log init ok
 }
}

The drawback is that previous code which makes use of J3D will not work without explicit call to init().

What can easily be done is to deprecate VirtualUniverse and clone it to J3DUniverse or so with the static method renamed to init() as above.

Could be good also if you could provide J3D as a bundle (means manifest file containing OSGi entries + bundle activator or blueprint as above).