在不同的JVM中运行Java命令 [英] Run java command in different JVM

查看:91
本文介绍了在不同的JVM中运行Java命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:我有一个客户端-服务器程序,其中客户端和服务器在不同的jvm中运行. 为了进行相同的测试,我想以编程方式在不同的JVM中调用Server,然后使用当前的jvm运行客户端并执行不同的C/S测试.

Goal: I have client-server program in which client and server runs in different jvms. To test the same, I want to invoke the Server in a different JVM programatically and then use current jvm to run the client and execute different C/S tests.

有什么方法可以以编程方式执行方法或在不同的jvm中运行Java命令吗?

Is there any way I can execute a method or run Java commands in different jvm programatically?

推荐答案

1)Java中运行过程最强大的工具是

1) The most powerful tool in java to run process is ProcessBuilder:

ProcessBuilder pb = new ProcessBuilder("java", "-server", "-jar", "yourJar.jar");

Process p = pb.start();

比使用流程能够操纵子进程,例如阅读 InputStream 破坏等等

Than using Process you are able to manipulate child process e.g. read InputStream, destroy e.t.c.

2)如果您能够同时编辑两个源代码

2) If you are able to edit both source code review this question to build efficient communication between JVM on the same host. If you cannot change code, simply create own loader which load Server and implements inter JVM communication and invoke methods you need, because it in the same JVM space.

这篇关于在不同的JVM中运行Java命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆