arton / rjb

Ruby Java Bridge
https://www.artonx.org/collabo/backyard/?RubyJavaBridge
GNU Lesser General Public License v2.1
117 stars 34 forks source link

Can't reload JVM.(Rjb::load after Rjb::unload) #34

Closed ghost closed 9 years ago

ghost commented 9 years ago

Can't reload JVM. sample is following.

#! ruby -Ku
# encoding: utf-8

require 'rjb'

Rjb::load
Rjb::unload
Rjb::load

line 8 occurs a error "in `load': can't create Java VM (RuntimeError)".

Environment: rjb 1.5.1.

> java -version
openjdk version "1.8.0_25"
OpenJDK Runtime Environment (build 1.8.0_25-b18)
OpenJDK 64-Bit Server VM (build 25.25-b02, mixed mode)

> ruby --version
ruby 2.1.4p265 (2014-10-27 revision 48166) 
arton commented 9 years ago

Yes. It's current JVM's restriction.

according to http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4712793

once a VM is created and destroyed, one cannot start another VM

Therefore if Rjb invoked DestroyJVM by unload, then Rjb never succeeded to create JVM. By the way, I wonder if you could explain me why do you like to unload and reload JVM ?

ghost commented 9 years ago

ok. My usecase is to kill java global(singleton) instances. details: I'm creating a testing framework for ApachePig(http://pig.apache.org/ Hadoop's DSL.) by using rjb. The language implementation have global context. Therefore, Killing jvm after a test case is little better to test separation.(It's NOT necessary, but better.)

ghost commented 9 years ago

oh... > JNI bug. Thanks for your explanation. I try to another way.

arton commented 9 years ago

Hi, thank you for you explanation. There are some way to do destroy singleton. One major way is to create it on a certain ClassLoader (for example, Tomcat's webapp context is separated from another context that's because ClassLoader is different (based on own WEB-INF) ). It's hard way but technically interesting. You may create new ClassLoader per a test and load the singleton on it.

ghost commented 9 years ago

very thanks! I'll try to create some loader.