Hi to all...
Mine is a very stupid problem, but i can't already solve it. A lot of times
i need to make my main class WAIT (until a certain number of seconds or a
change in variable content). I cannot apply an Listener because i don't need
user interaction.
If i make a While(true){ ...break when timer finish... } or
While(timer control) { empty }
i have a "little" problem: my class will use 100% of my Cpu in a cycle
(notwithstanding i do nothing inside the while).
I'd like to have a command like "wait" in old Basic...i cannot solve my
problem in other way.
I don't use multithreading, so i can't imagine to use wait...run commands in
multithreading. Also i think i can find a easier solution
Lots of kisses to all programmers....
Alex
Italy
_____________________________________
"Heard melodies are sweet,
but those unheard are sweeter;
therefore, ye soft pipes, play on,
- Not to the sensual ear, but, more endear'd,
Pipe to the spirit ditties of no tone."
(J. Keats, "Ode on a Grecian Urn")
Thomas Schodt - 18 Jun 2004 12:09 GMT
> i need to make my main class WAIT (until a certain number of seconds or a
> change in variable content).
[quoted text clipped - 4 lines]
> I don't use multithreading, so i can't imagine to use wait...run commands in
> multithreading.
You still have a single Thread (possibly more if you use awt/swing).
How about Thread.currentThread().sleep( seconds * 1000 );
Robert Klemme - 18 Jun 2004 16:07 GMT
> > i need to make my main class WAIT (until a certain number of seconds or a
> > change in variable content).
[quoted text clipped - 8 lines]
>
> How about Thread.currentThread().sleep( seconds * 1000 );
sleep() is static, so you don't need currentThread().
Kind regards
robert
Michael Amling - 18 Jun 2004 14:59 GMT
> Hi to all...
>
[quoted text clipped - 9 lines]
> I'd like to have a command like "wait" in old Basic...i cannot solve my
> problem in other way.
Have you tried
http://java.sun.com/j2se/1.3/docs/api/java/lang/Thread.html#sleep(long)
try {
Thread.sleep(milliseconds);
} catch (InterruptedException) {
}
--Mike Amling