How to execute java function in parallel with joptionpane
I want to execute a function in java, but for now I want to show the JOptionPane
user when the operation starts and when it ends, the problem is that if I don't click "Accept" buyton of the first JOptionPane
, my function won't run, I would like it to be automatically how can i do this? here is my code, i am 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);
+3
source to share
1 answer
Use ExecutorService
, I believe it should be easier to implement if you understand it. For 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 your other overloaded methods for your convenience. see documentation
0
source to share