How to prevent opening a new instance of MATLAB when multiple times run a Java program

时间:2015-10-30 22:11:20

标签: java matlab

I'm calling MATLAB program from Eclipse Java interface. I have used MatlabControl for it. When I run Java program multiple time, every time it opens a new instance of MATLAB, and that makes the computation slower.

Is it possible that I can prevent it from opening new instances of MATLAB? If possible, how can I do this?

If I have an already opened terminal of MATLAB, is it possible that the computation can simply use that terminal, instead of opening a new instance of MATLAB?

Any help would be appreciable.

2 个答案:

答案 0 :(得分:1)

The matlabcontrol can not connect to an already open instance of matlab, it can only create a new one. To prevent multiple matlab instances being opened, you can use proxy.exit() instead of proxy.disconnect() to close matlab when closing your application. To further use only a single instance of matlab across multiple instances of your java program, I see different possibilities but no very good one. Matlab comes with it's own JVM and you could start your java applications from the matlab console using. Officially documented, you can only call java functions from matlab, but other way round is possible as well. Please that matlab uses it's own jvm which might be outdated. Implement a server which is started one and exposes the matlabcontrol functionality. Use the matlab automation server where instances can be shared. It is .NET which can be used from java.

答案 1 :(得分:0)

以下是来自matlabcontrol教程的关于此问题的评论:

  

khai评论... @ gmail.com,2012年2月9日   要重用现有会话,需要首先断开先前的代理。这是一个例子,

MatlabProxyFactoryOptions options = new MatlabProxyFactoryOptions.Builder().setUsePreviouslyControlledSession(true).build();

MatlabProxyFactory factory = new MatlabProxyFactory(options);

MatlabProxy proxy = factory.getProxy();

...

proxy.disconnect();

proxy = factory.getProxy(); // this won't open a new Matlab session

它对我不起作用。但是一些人声称它完成了这项工作。

  

感谢。除了可以满足我要求的matlabcontrol之外还有其他方法吗? - user24094

matlabcontrol的其他替代方法: https://code.google.com/p/matlabcontrol/wiki/ApproachesToControl

希望你管理,这是一个真正的痛苦ITA工作....欢呼