Running java code in multiple jvm instances

I have a Windows service application and a client that interacts with a service using RMI. I need to run several concurrency tests with multiple clients, but I need each client to work with a different jvm instance, because there are some static variables in its code. I can do it? Any ideas?

+4
java concurrency jvm testing
source share
2 answers

Yes, you can do this using JDI - VirtualMachineManager (which you can get by calling Bootstrap.virtualMachineManager(); ), (at least one). Then you can call launch(); on this connector, which will provide you with a VM mirror for the virtual machine he creates. This mirror then allows you to remotely execute methods on this virtual machine.

You can configure as many remote virtual machines using this method as you see fit, although there is obviously a relatively large penalty for performing such actions, and this is a fair effort. If the efforts were not astronomical, I would personally defend the code to guarantee thread safety (using ThreadLocal ), and then you get rid of the need to worry about JDI (or a similar installation).

+5
source share

You can use a shell script to create a new client with its own set of parameters in a loop.

But in general. Running client code on multiple virtual machines just because there are some static variables that are shared is definitely not a good solution. The main problem is the client code , as already suggested, you can use ThreadLocal , ThreadPools or some synchronization logic to isolate the set of variables between different client threads.

+2
source share

All Articles