aspose file tools*
The moose likes Threads and Synchronization and the fly likes sleep() method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "sleep() method?" Watch "sleep() method?" New topic
Author

sleep() method?

Asleshkumar Thukaram
Greenhorn

Joined: Jan 25, 2001
Posts: 9
I'm just now learning the concepts of threads.....I tried to execute this pgm :
class td{
public static void main(String args[]){
Thread t=Thread.currentThread();
System.out.println("current thr " +t);
System.out.println("after name change ");
try{
for(int i=5;i>5;i--){
System.out.println(i);
t.sleep(1000);
}
}catch (InterruptedException e){
System.out.println("main thread interrupted");
}
}
}
But as expected, the pgm had to print the numbers 1,2,3,4 and 5, in an interval of 1 sec between each number, but it didn't print. The output just stopped with the print of "after name change ". Why doesn't that print the numbers??
George Toronto
Ranch Hand

Joined: Dec 30, 2000
Posts: 78

for(int i=5;i>5;i--){
System.out.println(i);
t.sleep(1000);
}

Hi,
loop is not coded as expected. you can code it like "for(int i=5;i<=1;i--)".
hope it helps
regds
George
George, We all make mistakes. It will be helpful if we help others rectify their mistakes. I have modified your message to remove inappropriate content.

[This message has been edited by Rahul Mahindrakar (edited January 28, 2001).]
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252

loop is not coded as expected. you can code it like "for(int i=5;i<=1;i--)". <br />
<br />
might work better.
- Peter
Peter , I have removed content that i feel is inappropriate.

[This message has been edited by Rahul Mahindrakar (edited January 28, 2001).]
George Toronto
Ranch Hand

Joined: Dec 30, 2000
Posts: 78
Oh, I am sorry, it is a type error. Thank you for correcting it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sleep() method?
 
Similar Threads
Thread Question
threads
Marcus Green Mock- doubt
Synchronized method Vs synchronized block
ThreadGroup .activeCount()