how to execute a java function in parallel with a joptionpane

253 views Asked by At

I want to execute a function in java, but meanwhile I want to show a JOptionPane to the user when the operation starts and when it ends, the problem is that if I don't push the "Accept" buyton of the first JOptionPane, my function doesn't starts, I'd like it to be automatically, how can I do that? here's my code, I'm using JRI interface for my function.


JOptionPane.showMessageDialog(null, "Leyendo archivos, espere un momento...","Importar archivos cel", JOptionPane.INFORMATION_MESSAGE);

REXP data = re.eval("rawdata <- read.celfiles(celFiles)");

JOptionPane.showMessageDialog(null, "Se han importado las muestras exitosamente.", "Importar archivos cel",JOptionPane.INFORMATION_MESSAGE);
1

There are 1 answers

0
Victor Anuebunwa On

Use ExecutorService, i believe it should be easier to implement if understood. example,

REXP data;
    try {
        ExecutorService newCachedThreadPool = Executors.newCachedThreadPool();
        Future<REXP> submit = newCachedThreadPool.submit(new Callable<REXP>() {
            @Override
            public Object call() throws Exception {
                return re.eval("rawdata <- read.celfiles(celFiles)");
            }
        });
        data = submit.get();
    } catch (InterruptedException | ExecutionException ex) {
        System.err.println(ex.getMessage);
    }
    JOptionPane.showMessageDialog(null, "Leyendo archivos, espere un momento...", "Importar archivos cel", JOptionPane.INFORMATION_MESSAGE);
    JOptionPane.showMessageDialog(null, "Se han importado las muestras exitosamente.", "Importar archivos cel", JOptionPane.INFORMATION_MESSAGE);

You can use other of its overloaded methods to your convenience. see documentation