delay function (java)

Programming, for all ages and all languages.
Post Reply
guest

delay function (java)

Post by guest »

hi
i m trying to put a delay function in my program which is supposed to be a very straight forward thing but its not working wat i m doing is that

Code: Select all

while(i++ < something){
      Thread.sleep(100);
       //do something now 
}
and i think this should work but wats happening is that rather having this 1 sec delay everytime the loop runs .. wat it does is that it stops for 1 sec and then print out the whole loop
can someone help me with this
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:delay function (java)

Post by Pype.Clicker »

keep in mind that there are 2 sort of output stream: buffered and unbuffered. On most systems, System.err is the unbuffered output (thus you can rely on the fact that the system will display what you give it as fast as it can), while System.out is buffered (if the system feels so, it can defer the display of your strings until it decides it has enough bytes to output so that it 'worth' the effort).

If you're doing some

Code: Select all

{
     Thread.sleep(100);
     System.out.println("A");
}
there are chances you actually wake up as expected, but the system output groups displays chunk by chunk ...

Hope it helps.
Post Reply