Java Builder - Multithreading issues

2 views (last 30 days)
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

Accepted Answer

Titus Edelhofer
Titus Edelhofer on 10 Jul 2011
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
  7 Comments
Artik Crazy
Artik Crazy on 13 Jul 2011
Hello again, thank you for your help!
Titus, I couldn't figure out the example you suggested :( Can you please give me the link again?
Friedrich, I tried to use batches in my application and it seems to be working - I will test it in full Java application tomorrow. Thank you again for an advice!
Artik Crazy
Artik Crazy on 14 Jul 2011
It does not work... I get the same error for the example specified and my own application: "The local scheduler cannot be used in deployed applications".
I Googled and understood that it is not possible to compile and deploy applications that use the local scheduler. I don't understand why Mathworks posted this example if it is not possible at all...
I'm really confused now...

Sign in to comment.

More Answers (0)

Categories

Find more on Java Package Integration in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!