Q:

Timers In A Game

Im trying to code a 2D java game. I have init(), render(), update() methods as usual. The thing I want to figure out is, I would like to have timers attached to objects. For example a powerup randomly spawns in the map, but it should exist for 5 seconds. Or when the user hits the "Play" button, I would like to make him wait for 3 seconds, and at the same time do the background work (load resources, create the scene etc). I mean I would like to have the time counters work at the background, while I'm doing the stuff normally in the game at the same time. How can I implement this? Any helps, even simple ideas would be appreciated!
Edit: I'm using slick2D library and Graphics class for drawing to the screen.

A:

If you want to use a timer there are multiple ways to do so, as stated previously there is the:
Thread.sleep(milli);
or another way I commonly use is to create a new class and make a Timer there using a while loop: 
public class Timer implements Runnable {

    private long startTime, runTime;

    public Timer(long runTime){//set runtime
         this.runTime = runTime;
    }

    public void run(){
       startTime = System.currentTimeMillis();//gets system's current time in milliseconds
       while(System.currentTimeMillis() - startTime < runTime ){//loops until the current time - the start time is less then the specified run time. 
        //Runs this
       }
    }
}

