MATLAB hangs when I try to use the java package jdde, but only for the first time after a system reboot
Asked Answered
F

3

18

I'm using the external java package jdde in MATLAB. Please note that for the following example, the DLL file that comes with the package needs to be on the MATLAB librarypath. The method to do this is different depending on your MATLAB Version.

Using jdde in MATLAB works fine, except for the first time after I reboot the computer or I logoff/logon in Windows. When I run the following code for the first time after a computer reboot, MATLAB will stay in busy mode forever (with 0% CPU). When this happens, I kill the MATLAB process in the task manager and restart MATLAB. When I run the same code again, it will execute instantly (not staying busy forever).

javaaddpath('C:\pretty-tools-JDDE-1.0.2.jar')
a =  com.pretty_tools.dde.client.DDEClientConversation;
a.connect('','');

To sum it up, the above code will cause MATLAB to stay busy forever the first time I run it after a system reboot or user logoff/logon. When I run it again after killing the MATLAB process, it will work perfectly fine (not hanging up MATLAB).

I have seen this behavior on different computers, and in different Versions of MATLAB (2010 and 2012). I'm using Windows 7 x64.

In the code example, the a.connect command is the one that causes MATLAB to stay busy forever. Putting this command in a try/catch block would not help, because the a.connect doesn't cause an error, it just never does continue.

I'm not sure if this problem is caused by MATLAB or by the java package. Any ideas how to get rid of this behavior would be much appreciated.

Note: The input argument of a.connect does not matter, it will always hang, so I just gave '' as input in this example.

Ferryboat answered 16/10, 2012 at 9:6 Comment(2)
To determine if it is matlab or the package, you can do a simple test by wrapping same commands as above in stand alone program - just write short wrapper that loads libray and calls a.connect() in C++ or java. If you do that and execute it under the similar conditions as you are testing in matlab, would it hang or not?Elnoraelnore
How do you tell it is hung during connect? Do you have any code after a.connect? You have to call a.disconnect explicitly in case JVM may hang with some daemon threads are running native code.Gules
H
1

Code hangs without any know reason in DdeInitialize() method. New build JDDE-2.0.3 contains workaround for this problem.

Hydromancy answered 18/9, 2013 at 13:6 Comment(0)
S
1

Try running the add path command on its own so that there is a second or two before it tries to execute code dependant on the jar. I have found this to often be the problem with intermittent issues having to do with jars in Matlab

Soothe answered 18/5, 2013 at 2:57 Comment(1)
This has happened to me with multiple packages. Matlab needs time to register where the resource is. Thumbs upBabism
H
1

Code hangs without any know reason in DdeInitialize() method. New build JDDE-2.0.3 contains workaround for this problem.

Hydromancy answered 18/9, 2013 at 13:6 Comment(0)
T
0

Switch over to classic mode initially so that u will get rid of that.

Thyroid answered 21/3, 2013 at 12:28 Comment(1)
I don't know about a classic mode in MATLAB or jdde. Could you point me in the right direction? What do you mean exactly?Ferryboat

© 2022 - 2024 — McMap. All rights reserved.