I have basicly to boolean, A and B.
I want to make A true for a time. And after this time passed make B go true for another time.
I have tried this :
private void setStatusTrueForDuration(String name, long durationInMilliseconds) { if (name.equals("A")) { A= true; ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); executor.schedule(() -> A = false, durationInMilliseconds, TimeUnit.MILLISECONDS); } else if (name.equals("B")) { B = true; ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); executor.schedule(() -> B = false, durationInMilliseconds, TimeUnit.MILLISECONDS); } }
Can someone help me to do that ?