简体   繁体   中英

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

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.

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.

  1. 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, butother way round is possible as well . Please that matlab uses it's own jvm which might be outdated.
  2. Implement a server which is started one and exposes the matlabcontrol functionality.
  3. Use the matlab automation server where instances can be shared. It is .NET which can be used from java.

Here is a comment from matlabcontrol tutorial regarding this problem:

Comment by khai...@gmail.com, Feb 9, 2012 To reuse the existing session, the previous proxy needs to be disconnected first. Here is an example,

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

It did not work for me. But some ppl claim it did the job.

Thanks. Is there any other way apart from matlabcontrol that can fulfill my requirement? – user24094

Other alternatives to matlabcontrol here: https://code.google.com/p/matlabcontrol/wiki/ApproachesToControl

Hope you manage, its a real pain ITA to work like that.... cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM