I have many facilities. Whenever facilities are turned on they call some class so that they can run at fixed Scheduled rate. If the facilities is closed i need to shutdown thread for that particular facility. How can i achieve that i am getting RejectedExecutionException when i try to shutdown and reopen the same facility later . Thanks for help. My code is similiar like as follows:
private static final ScheduledExecutorService svc = Executors
.newSingleThreadScheduledExecutor();
private static ScheduledFuture<?> syncThreadHandle = null;
public static void start(final String str1, final String str2) {
syncThreadHandle = svc.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
System.out.println("First string for this thread str1 " + str1
+ " Str2 " + str2);
}
}, 0, 1, TimeUnit.MINUTES);
}
public static void stop(final String str1, final String str2) {
svc.shutdown();
}
// and from another class i am using this.
public static void main(String args[])
{
ProcessFixedRun.start("hi", "hello");
ProcessFixedRun.start("hi agaIN", "hello again");
ProcessFixedRun.stop("hi", "hello");
}
How can i find the thread for that particular facility. I am not good at threads. Any help will be appreciated thanks
Can you store the ScheduleFuture in a map then cancel based on the key?
The key can be either str1 or str2 (or both?).