-
Notifications
You must be signed in to change notification settings - Fork 7
Multi-thread use case #19
Comments
My impression is that one can only have exactly one JVM in one process in total, and not sequentially: https://docs.rs/rucaja/0.4.2/rucaja/struct.Jvm.html#method.new If i understand correctly, sharing the same JVM from different Rust threads should be safe, since we attach/detach using JvmAttachment ( An alternative could be to use different Rust processes. |
And thanks by the way for using Rucaja. I am interested in making it more usable, so your feedback is very appreciated. |
I have no deep JNI knowledge myself. @fpoli, @treyzania, @tupshin, @Dushistov do you have any experience regarding multithreading and JNI? Is the above approach sufficient? |
I'm also not an expert, but I just found that "according to docs, only one thread can use use JVM at a time". So, it should be possible by using a |
@kud1ing I'm a bit late to this party, but I would assume that we could restructure the APIs a bit so that we always return a
EDIT: I'm now realizing that |
My code is in a multi-thread setting, inside each thread, there is a need to call jvm functions.
I find that the "jvm" instance itself cannot be constructed separately inside each thread, by loading the classpath with proper options. In this case, it will panic with a message:
This alternative seems to be putting JVM construction code before spawning threads and then passing as parameters.
The problem is that I'm not quite sure whether this will cause data race internally at the JVM side.
Since I know little about JNI and would like to be merely a "user" of rucaja, Could you please advise?
The text was updated successfully, but these errors were encountered: