I have a simple m-file
function [fRate,Height,Width] = media(filename)
obj = mmreader(filename);
fRate = obj.FrameRate;
Width = obj.Width;
Height = obj.Height;
end
Which I have successfully compiled using MATLAB Builder JA into a .jar file.
I have tested the .jar file in a single threaded application and it work with no problem.
The error came when I use it in a multi threaded GUI application. I run the .jar as a thread in one of the class I created and the following error occur.
An unexpected error has been detected by Java Runtime Environment:
EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d9c08b0, pid=5920, tid=4788
Java VM: Java HotSpot(TM) Client VM (10.0-b19 mixed mode windows-x86) Problematic frame:
C [jvm.dll+0x1108b0]
After debugging, I found that the error occur when my thread is calling
media = new Media();
(I name my .jar as Media.jar)
This is my Java code:
// mediaProperty.java
public class mediaProperty implements Runnable {
public void mediaProperty() {
Matlab_options matlab = new Matlab_options();
Object[] mediaProp = null;
java.util.List lstMedia = new ArrayList();
Media media = null;
try {
media = new Media();
...
mediaProp = media.media(3, lstMedia);
...
} catch (Exception p) {
System.out.println("Exception: " + p.toString());
} finally {
MWArray.disposeArray(mediaProp);
if (media != null) {
media.dispose();
}
}
}
public void run() {
mediaProperty();
}
}
// GUI.java
private Thread mediap;
if (mediap == null) {
mediap = new Thread(new mediaProperty());
mediap.start();
}
What is wrong? Is it my code?