java 启动多个jvm实例,在多个jvm实例中运行java代码

该博客探讨了如何在Windows服务应用中通过JDI(Java Debug Interface)创建多个JVM实例,每个客户端运行在不同的JVM上,以进行并发测试。由于代码中存在静态变量,这种方法旨在避免线程安全问题。博主建议通过使用ThreadLocal修复代码以确保线程安全性,从而消除对复杂JDI设置的需求。
摘要由CSDN通过智能技术生成

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?

解决方案

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.)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值