joeferner / node-java

Bridge API to connect with existing Java APIs.
MIT License
1.87k stars 282 forks source link

API for destroying JVM #144

Open drobiazko opened 10 years ago

drobiazko commented 10 years ago

Is there any way to invoke this deconstructor from Node code? We'd like to have an API for destroying the JVM.

joeferner commented 10 years ago

Not really. Can you give me some insight into why you might want to do this? Once the JVM is destroyed any references to the Java object in JavaScript land would become unusable, then we would need a method to restart it I guess.

drobiazko commented 10 years ago

We have a Java worker that executes Java jobs. Each job is actually a completely independent Java app with its own set of dependencies. We would like to isolate the classpaths of these Java jobs. I guess just clearing the classpath array won't help.

Do you have any ideas?

jzakrzewski commented 10 years ago

Last time I've tried to do so, I've hit a long-standing bug that didn't allow you to re-initialize JVM for the process once it has been deinitialized. I don't know if situation is any different right now.

jsdevel commented 10 years ago

We could try moving that into a separate method that can be callable from both the deconstructor and a module method. We'd need to define a way to initialize it again though.

drobiazko commented 10 years ago

This would be awesome. Let me know if you need an alpha tester for this feature.

DemiMarie commented 7 years ago

@jzakrzewski I doubt it. The only way to do this is to unload the JVM shared library.

Tomas2D commented 2 years ago

Any progress on this?

DemiMarie commented 2 years ago

Doubtful. The JVM simply doesn’t have good unloading support right now. @Tomas2D what is your use-case? @drobiazko you can do something similar with classloader trickery.

Tomas2D commented 2 years ago

For example using application with need of different database connections based on application module. Next and not least is E2E tests, where Jest obviously fails to init multiple JVM.

DemiMarie commented 2 years ago

For example using application with need of different database connections based on application module.

Is classloader trickery an option?

Next and not least is E2E tests, where Jest obviously fails to init multiple JVM.

I think your best option is going to be using a cached JVM instance for all tests, or spawning a separate process.

Tomas2D commented 2 years ago

I was able to achieve caching via pretty hacky way in Jest with help of this article http://www.petecorey.com/blog/2018/11/05/bending-jest-to-our-will-caching-modules-across-tests/ .

But I do not understand what do you mean by classloader trickery, I am using this package - https://github.com/CraZySacX/node-jdbc

DemiMarie commented 2 years ago

But I do not understand what do you mean by classloader trickery, I am using this package - https://github.com/CraZySacX/node-jdbc

I know basically nothing about JDBC, but I would imagine there is a way to have multiple database connections in the same JVM.

Tomas2D commented 2 years ago

I see your point, but it looks like, that the mentioned library does not supports that.

DemiMarie commented 2 years ago

Please file a ticket with that library.