在多线程Java应用程序中调用已编译的m文件(.jar)时出错 [英] Error when calling compiled m-file(.jar) in a multi threaded Java app
问题描述
我有一个简单的m文件
function [fRate,Height,Width] = media(filename)
obj = mmreader(filename);
fRate = obj.FrameRate;
Width = obj.Width;
Height = obj.Height;
end
我使用MATLAB Builder JA成功编译成.jar文件。
Which I have successfully compiled using MATLAB Builder JA into a .jar file.
我在单线程应用程序中测试了.jar文件,它没有问题。
I have tested the .jar file in a single threaded application and it work with no problem.
错误我在多线程GUI应用程序中使用它时出现了。我在我创建的类之一中运行.jar作为线程,并发生以下错误。
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.
检测到意外错误
by Java Runtime Environment:
An unexpected error has been detected by Java Runtime Environment:
EXCEPTION_ACCESS_VIOLATION
(0xc0000005)at pc = 0x6d9c08b0,
pid = 5920,tid = 4788
EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d9c08b0, pid=5920, tid=4788
Java VM:Java HotSpot(TM)客户端VM
(10.0-b19混合模式windows-x86)
有问题的框架:
Java VM: Java HotSpot(TM) Client VM (10.0-b19 mixed mode windows-x86) Problematic frame:
C [jvm.dll + 0x1108b0]
C [jvm.dll+0x1108b0]
调试后,我发现当我的错误发生时线程正在调用
media = new Media();
(我将我的.jar命名为Media.jar)
After debugging, I found that the error occur when my thread is calling
media = new Media();
(I name my .jar as Media.jar)
这是我的Java代码:
// mediaProperty.java
This is my Java code:
// mediaProperty.java
public class mediaProperty实现Runnable {
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
// GUI.java
私人线程媒体;
if(mediap == null){
mediap = new Thread(new mediaProperty());
mediap.start();
}
if (mediap == null) {
mediap = new Thread(new mediaProperty());
mediap.start();
}
有什么问题?这是我的代码吗?
What is wrong? Is it my code?
推荐答案
我的猜测是MATLAB要求你从一个线程中访问它。你说它在单线程应用程序中工作,也许你需要启动一个专用线程来与MATLAB交互以使其正常工作。
My guess is that MATLAB requires you to access it from exactly one thread. You say it works in a single threaded application, perhaps you need to start a dedicated thread for interacting with MATLAB to get this to work correctly.
这篇关于在多线程Java应用程序中调用已编译的m文件(.jar)时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!