ScheduledExecutorServiceを使用して、1分ごとに以下のコードが実行中であると仮定します。Java - ScheduledExecutorServiceを正しく停止する方法
このジョブはstartBatch.shファイルによってトリガーされます。
public class TestScheduledExecutorService {
public static void main (String a[]) {
ScheduledExecutorService service = null;
try {
TestObject runnableBatch = new TestObject() {
int i = 0;
@Override
public void run() {
testMethod (++i);
}
};
service = Executors.newSingleThreadScheduledExecutor();
service.scheduleAtFixedRate(runnableBatch, 0, 20, TimeUnit.SECONDS);
} catch (Exception e) {
e.printStackTrace();
}
}
}
問題が存在する場合、ライブ後にこのデーモンプロセスを正しく停止する方法はありますか。
Not GhostCat、プロセスを停止する唯一の方法は、リスニングポートを正しく使用して殺すことです。 – DEADEND
ありがとう&注目GhostCat。 @ GhostCat。 – DEADEND
すばらしいです。もう一度ありがとうございます。 – DEADEND