How Java handle the Time pause

Hi Everyone,

I want to write a simple program for a class to doing somthing after a specific time pause.

For example, A class print out message after the time pasue 15s, such as following:

-

class aaa extends Thread

public run(){

try{

sleep(15000);

System.out.println("after a time pause");

}catch(Exception e){

}

}

-

But it is having other method to doing a time pause without using thread programming.

Thank You very much for everyone can help

[536 byte] By [sherman_liu7687@yahoo.com.hka] at [2007-11-27 2:42:15]
# 1
Thread.sleep(15000);Sleep is a static method and it will make the current thread sleep.
kajbja at 2007-7-12 3:06:45 > top of Java-index,Java Essentials,Java Programming...
# 2

You shouldn't (in general) ever need to extend Thread.

You should call static members either by qualifying them with the class name, or by using import static.

import static java.lang.Thread.sleep;

class Sleeper implements Runnable {

public void run() {

try {

sleep(15000);

System.out.println("after a time pause");

} catch (InterruptedException ex) {

System.err.println("woke up");

}

}

}

>But it is having other method to doing a time pause without using thread programming.

In Java SE, Thread.sleep() is how you pause the execution of a thread, including the main thread of a program. Why do you want to use a different method?

pm_kirkhama at 2007-7-12 3:06:45 > top of Java-index,Java Essentials,Java Programming...
# 3
my problem has been solved, thank you everyone
sherman_liu7687@yahoo.com.hk at 2007-7-12 3:06:45 > top of Java-index,Java Essentials,Java Programming...