[scilab-Users] Scilab called within a Java thread
Sylvestre Ledru
sylvestre.ledru at scilab.org
Sat May 7 20:56:22 CEST 2011
Hello,
Which version of Scilab are you using ? What do you mean by "crashes" ?
Due to constraints with Scilab family 5, Javasci is not designed to
manage several versions of Scilab at the same time. This has been
reported here: http://bugzilla.scilab.org/show_bug.cgi?id=6069
However, you should get an error saying that Scilab is already started.
Sylvestre
Le vendredi 06 mai 2011 à 11:08 -0700, scheiber a écrit :
> Hi,
>
> My problem is the Scilab calling within a Java thread. The bellow example
> works when the number of threads (noThreads) is 1 but increasing this
> number it crashes.
>
> import org.scilab.modules.javasci.Scilab;
> import org.scilab.modules.types.ScilabType;
> import org.scilab.modules.types.ScilabDouble;
> import java.util.concurrent.*;
>
> public class TestThreadScilab{
> static Scilab sci;
> static int noThreads=1;
>
> public static void main(String... args){
> try{
> sci=new Scilab();
> }
> catch(org.scilab.modules.javasci.JavasciException e) {
> System.err.println("An exception occured: " +
> e.getLocalizedMessage());
> System.exit(1);
> }
> ExecutorService executor=Executors.newFixedThreadPool(noThreads);
> for(int i=0;i<noThreads;i++){
> Fir fir=new Fir(i);
> executor.execute(fir);
> }
> try{
> executor.shutdown();
> while(!executor.isTerminated());
> sci.close();
> }
> catch(Exception e){}
> System.out.println("Finished");
> }
>
> static class Fir extends Thread{
> private int index;
>
> Fir(int index){
> this.index=index;
> }
>
> public void run(){
> System.out.println("Thread "+index+" started");
> try{
> if(sci.open()){
> double ind=index*1.0d;
> ScilabDouble sci_ind=new ScilabDouble(ind);
> sci.put("u",sci_ind);
> sci.exec(new String[]{"v=u+10","disp(v)"});
> ScilabDouble sci_v=(ScilabDouble)sci.get("v");
> if(!sci_v.isEmpty()){
> double[][] v=sci_v.getRealPart();
> System.out.println("Index "+index+" : "+v[0][0]);
> }
> }
> else{
> System.out.println("Could not start Scilab ");
> }
> }
> catch(org.scilab.modules.javasci.JavasciException e) {
> System.err.println("An exception occured: " +
> e.getLocalizedMessage());
> }
> }
> }
> }
>
>
>
> --
> View this message in context: http://mailinglists.scilab.org/Scilab-called-within-a-Java-thread-tp2909258p2909258.html
> Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
More information about the users
mailing list