私は自分のアプリケーションのバックグラウンドタスクを継続的に実装しようとしています。 私はScheduledExecutorService
クラスを使用しています。 私は2つのサービスを持っていますService A
とService B
は両方とも、一定の時間間隔の後に常に実行されるタスクを持っています。私はこれを次のように使用しましたService A
とService B
ScheduledExecutorService。 2つの別々のサービスでいくつかの時間間隔の後に2つのタスクを実行する方法
これは両方のサービスクラスで共通のコードです。
Runnable postNotificationRunnable = new Runnable() {
@Override
public void run() {
// statements here}
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
scheduledExecutorService.scheduleAtFixedRate(postNotificationRunnable, 0, 1000, TimeUnit.SECONDS);
私はアプリの両方のサービスが開始されるが、他の1が実行されないService A
実行の唯一のみscheduledExecutorServiceを実行すると問題があります。私は間違って何をしていますか? P.私は初めてScheduledExecutorServiceを使用しています。