Tapas Bose
Tapas Bose

Reputation: 29806

Rescheduling of a ScheduledExecutorService

The following piece of code is called from a JMenuItem's ActionListener. Simply it launches a jar file.

ScheduledExecutorService schedulerExecutor = Executors.newScheduledThreadPool(2);
Callable<Process> callable = new Callable<Process>() {

    @Override
    public Process call() throws Exception {
        Process p = Runtime.getRuntime().exec("cmd /c start java -jar D:\\MovieLibrary.jar");
        return p;
    }
};
FutureTask<Process> futureTask = new FutureTask<Process>(callable);
schedulerExecutor.submit(futureTask);
schedulerExecutor.shutdown();               

System.exit(0);

But the problem is, it is execution only once. Not repeatedly. That means the Process p = Runtime.getRuntime().exec("cmd /c start java -jar D:\\MovieLibrary.jar"); is not called for second time.

How can I make to right?

Any suggestion is appreciable. Thanks in advance.

Upvotes: 0

Views: 843

Answers (1)

Erhan Bagdemir
Erhan Bagdemir

Reputation: 5327

newScheduledThreadPool(2) doesn't mean that the thread runs twice. It is the size of the pool. "submit" the task twice if you want to run it for second time.

schedulerExecutor.submit(futureTask);
schedulerExecutor.submit(futureTask);

Upvotes: 1

Related Questions