Hi,

I need to create a time delay before I call a method.

public void brewDrink(CoffeeMachine coffeemachine) {
        try {
            coffeemachine.displayDrinkBrewing();
            Thread.sleep(7000);
            setDrinkReady(coffeemachine);
        } catch (InterruptedException ex) {
        }
    }

This doesn't work, the method isn't called. Any help or pointers are welcome!

Recommended Answers

All 5 Replies

Timer and TimerTask (java.util and not javax.swing)

I'm looking trough the API doc and I don't really understand how to implement it... I didn't find any really helpful tutorials, do you know about any?

This doesn't work, the method isn't called. Any help or pointers are welcome!

What makes you think the method isn't being called? I would guess that it takes about 7 seconds for that whole method to finish - and it only updates the display after it's done.

If my guess is correct, read this thread from a couple of days ago: http://www.daniweb.com/forums/thread241390.html

Thread.currentThread().sleep(1000);//sleep for 1000 ms

Thread.currentThread().sleep(1000);//sleep for 1000 ms

Thanks that was particularly helpful, especially because the Java guys haven't put a word about it anywhere in the docs.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.