Java Builder - Multithreading issues
2 次查看(过去 30 天)
显示 更早的评论
Hello!
I built and compiled my first serious Matlab program to Java class using the Java Builder. I wrote Java driver, which converts the necessary data types from Java to Matlab.
But now I have a problem - I try to use the same class in two parallel threads in my Java application and keep getting exceptions. When I run only one thread it works fine. What can be the problem? Please help me...
Update:
My intention is to use a Random Forest Ensemble, trained previously in Matlab, in a Java application. My Matlab function, which I compiled, using deploytool is:
function [Probability]=PredictingTest (Predictor)
load (['D:/Test/Tree.mat'], 'Tree')
[~, prob]=predict(Tree , Predictor);
Probability=prob(:,1);
end
Where:
Predictor input is an integer between -10 to 10. Probability output is a double between 0 to 1. Tree is a .mat file with a CompactTreeBagger object stored in it. Next I deploy the jar files to my Eclipse project, and try to run this Java code:
/* Necessary package imports */
import com.mathworks.toolbox.javabuilder.*;
import PredictTest.*;
public class predict_test {
static MWNumericArray rhs = null; /* Stores input value */
static PredictTest prediction;
static Object[] result = null; /* Stores the result */
public static void main(String[] args) {
try {
prediction = new PredictTest();
rhs=new MWNumericArray(5,MWClassID.DOUBLE);
result=prediction.PredictingTest(1, rhs);
}
catch (MWException e) {
e.printStackTrace();
}}}
Segmentation violation detected at Fri Jul 08 12:02:26 2011:
Configuration:
MATLAB Version: 7.11.0.584 (R2010b)
Processor ID: x86 Family 6 Model 14 Stepping 5, GenuineIntel
Virtual Machine: Java 1.6.0_22-b04 with Sun Microsystems Inc. Java HotSpot™ Client VM mixed mode
0 个评论
采纳的回答
Titus Edelhofer
2011-7-10
Hi,
which version of MATLAB are you using? And could you post both the exception you are seeing and how you call your class?
Titus
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Java Package Integration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!