Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run java code in multiple jvm instances

I have a windows service application and a client which communicates with service using RMI. I need to do some concurrency testing with multiple clients but I need every client runs to different jvm instance because there are some static variables in its code. Can I do that ? Any ideas?

like image 822
Petros Tsialiamanis Avatar asked Mar 23 '23 20:03

Petros Tsialiamanis


1 Answers

Yes, you can do this using JDI - VirtualMachineManager (which you can get by calling Bootstrap.virtualMachineManager();) provides (at least one) launching connector. You can then call launch(); on this connector which provides you with a VM mirror for the VM it creates. This mirror then lets you remotely execute methods on this VM.

You can set up as many remote VMs using this method as you choose, though obviously there's a relatively big performance penalty for doing things this way, and it's a fair bit of effort. Unless the effort would be astronomical, I'd personally advocate fixing the code to guarantee thread safety (using ThreadLocal) and then you do away with the need to worry about JDI (or a similar setup.)

like image 146
Michael Berry Avatar answered Apr 06 '23 13:04

Michael Berry