私は多くの施設を持っています。施設が稼動するたびに、一定の定刻率で稼働できるようにクラスが呼び出されます。施設が閉鎖されている場合は、その特定の施設のスレッドを停止する必要があります。後で同じ施設をシャットダウンして再度開くときに、RejectedExecutionExceptionを取得していることをどうすれば達成できますか?手伝ってくれてありがとう。私のコードは次のように類似しています:ScheduledExecutorServiceで選択したスレッドのみをシャットダウンする方法はありますか?
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();
}
//そして私はこれを使っています。
public static void main(String args[])
{
ProcessFixedRun.start("hi", "hello");
ProcessFixedRun.start("hi agaIN", "hello again");
ProcessFixedRun.stop("hi", "hello");
}
どのように特定の施設のスレッドを見つけることができますか?私はスレッドにうまくいきません。どんな助けもありがとうございます
スレッドを中断することはできますが、サービスは新しいスレッドを生成します – Adrian