Page 1 of 1

delay function (java)

Posted: Mon Oct 13, 2003 12:17 pm
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

Re:delay function (java)

Posted: Fri Oct 24, 2003 12:45 am
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.