Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Tools / June 2004

Tip: Looking for answers? Try searching our database.

HELP - How can I tell to my program WAIT?

Thread view: 
Alessandro Giambruno - 18 Jun 2004 11:55 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.