How using sleep() method ?

Hello every body and marry christmas for all :)I want to stop my program during 1 second, how can I do that and witch package must I use,thank you.
[168 byte] By [lioussaa] at [2007-10-1 1:15:09]
# 1
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Thread.html
annie79a at 2007-7-8 1:31:21 > top of Java-index,Security,Event Handling...
# 2
Switch off the lights and sleep will come by.Merry Christmas to you.***Annie***
annie79a at 2007-7-8 1:31:21 > top of Java-index,Security,Event Handling...
# 3
Yes I've seen the link, but I want to use the method without thread!Cna I do it and how?thank you.
lioussaa at 2007-7-8 1:31:21 > top of Java-index,Security,Event Handling...
# 4

Hi

I think it抯 because of the Christmas season I posted a question my self and got similar answers. It抯 a very useful forum though. Mary Christmas to you all cheers.

try{

//do what you want to do before sleeping

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

//do what you want to do after sleeptig

}

catch(ItrerruptedException ie){

//If this thread was intrrupted by nother thread

}

WirajRa at 2007-7-8 1:31:21 > top of Java-index,Security,Event Handling...
# 5

> > try{

>//do what you want to do before sleeping

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

> 00 ms

>//do what you want to do after sleeptig

> }

> catch(ItrerruptedException ie){

> //If this thread was intrrupted by nother thread

> }

>

Actually, since sleep is a static method, it's better form to just use Thread.sleep(1000) and skip the currentThread() part.

jverda at 2007-7-8 1:31:21 > top of Java-index,Security,Event Handling...
# 6

> Yes I've seen the link, but I want to use the method

> without thread!

> Cna I do it and how?

You can't to anything in Java without a Thread. Everything executes in the context of a Thread.

If you mean can you do it without explicitly starting an additional thread (beyond the main thread), then yes, you can. as pointed out above, just call the static method Thread.sleep(). That always acts on the current thread.

jverda at 2007-7-8 1:31:21 > top of Java-index,Security,Event Handling...
# 7
A great thanks for all the participants.I think that i have understoud!sleep() method is obligatory used in thread!.@+ elias
lioussaa at 2007-7-8 1:31:21 > top of Java-index,Security,Event Handling...
# 8
GJ m8 'n happy hollidays
einarorna at 2007-7-8 1:31:21 > top of Java-index,Security,Event Handling...