0

This code does literally nothing until you add "System.out.println();" between the 3rd and 4th lines.

@Override
public void run() {
    while (true){
        if(endsIn != 0 && System.currentTimeMillis() < endsIn){
            endsIn = 0;
            adapter.check();
        }
    }
}
Swimer
  • 43
  • 5
  • How do you expect `System.currentTimeMillis() < endsIn` to ever be true? And what does `adapter.check()` do? – Federico klez Culloca May 31 '22 at 09:49
  • I think you are showing too little of your code. Please provide a [mcve]. I think you are probably doing this as part of some multithreaded program, which many times is "solved" by introducing a print. – RealSkeptic May 31 '22 at 10:32
  • @FedericoklezCulloca we don't see where `endsIn` gets the initial value. It may well be set to a value like `System.currentTimeMillis() + 100` or whatever. That's why a [mcve] is important. – RealSkeptic May 31 '22 at 10:34
  • @RealSkeptic and that's why I asked :) (now that I re-read my comment, maybe the phrasing wasn't really the best to convey the question) – Federico klez Culloca May 31 '22 at 10:57
  • 1
    Might be dealing with https://stackoverflow.com/questions/25425130/loop-doesnt-see-value-changed-by-other-thread-without-a-print-statement – Sotirios Delimanolis May 31 '22 at 11:39

1 Answers1

-1
System.currentTimeMillis();

provides a long, as a example "1653990772050".

It would never be 0

If you want to track a Running time you have to define a start time.

long startTime = System.currentTimeMillis();
long runtime = System.currentTimeMillis()-startTime;

Stored in runtime is now the time difference in ms.

  • Where did the OP say that they want to track running time? Also, they don't compare the system time to 0, they compare it to a value that has been set somewhere. – RealSkeptic May 31 '22 at 10:30