Image

Imagecyb3rj wrote in Imagejava_dev

waiting five seconds

Java... there are 100 ways to do the same thing. I want to gracefully wait five seconds.


private void waitASec() {
    Calendar now = Calendar.getInstance();
    long milliTime = now.getTimeInMillis();

    boolean ok = false;
    while (!ok) {
        long currentTime = Calendar.getInstance().getTimeInMillis();
        if ((currentTime - milliTime) > 5000) {
           ok = true;
        }
    }
}


Do you have something more elegant?

TIA

---
No, I'm not a college or high school student looking for an answer to a homework assignment. I learned to program with Pascal and Basic (yes, pity me if you would like...). I'm relatively new to Java and I'm looking for a more graceful way to do this.