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
}
> > 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.
> 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.