Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > sleep for 30 millis in Java ?

sleep for 30 millis in Java ?
Thread Tools
Fresh-Faced Recruit
Join Date: Mar 2001
Status: Offline
Reply With Quote
Apr 17, 2001, 09:46 AM
 
Is there a way in java to do nothing in a program say for thirty milliseconds without using Threads.sleep() method call. I looked up the documentation but could not find anything.

Thanks,
Erol
     
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status: Offline
Reply With Quote
Apr 17, 2001, 11:09 AM
 
you could get the current time, enter a loop that just checks the time against 30 millis from now.

But why not use threads?
signatures are a waste of bandwidth
especially ones with political tripe in them.
     
Junior Member
Join Date: Apr 2001
Location: Seattle, WA, USA
Status: Offline
Reply With Quote
Apr 17, 2001, 12:50 PM
 
Originally posted by Kristoff:
you could get the current time, enter a loop that just checks the time against 30 millis from now.

But why not use threads?
There's no reason to not just use the static method in Thread.

Code:
void pause(long millis) { try { Thread.sleep(millis); } catch (InterruptedException e) { } } ... pause(30);
You are using threads in every Java program you write, since even if your program has only a single thread of control, it is by definition in a thread which is separate from the event system, the garbage collector, etc.

-tw

     
esavas  (op)
Fresh-Faced Recruit
Join Date: Mar 2001
Status: Offline
Reply With Quote
Apr 17, 2001, 05:35 PM
 
Thanks a lot guys !
You have helped me a great deal.

     
tie
Professional Poster
Join Date: Feb 2001
Status: Offline
Reply With Quote
Apr 19, 2001, 12:33 AM
 
Is the equivalent way of sleeping threads in Obj C to

[myThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:.03]];

? This seems reasonable but it also seems a bit heavier than it needs to be. Do you also have to put in an autorelease command, e.g.,

[myThread sleepUntilDate:[[NSDate dateWithTimeIntervalSinceNow:.03] autorelease]];

?
The 4 o'clock train will be a bus.
It will depart at 20 minutes to 5.
     
ids
Fresh-Faced Recruit
Join Date: Apr 2001
Location: UK
Status: Offline
Reply With Quote
Apr 19, 2001, 04:44 AM
 
A quick note of caution:
if you are using the Thread.sleep() method you should be aware that the time the thread will sleep for will be _at least_ the time you specify, but will quite likely be more than that so you cannot depend on sleep for critical timing.



[This message has been edited by ids (edited 04-19-2001).]
     
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status: Offline
Reply With Quote
Apr 19, 2001, 10:45 AM
 
That's why Java isn't used in real time systems -yet
signatures are a waste of bandwidth
especially ones with political tripe in them.
     
Junior Member
Join Date: Apr 2001
Location: Seattle, WA, USA
Status: Offline
Reply With Quote
Apr 19, 2001, 02:57 PM
 
Originally posted by Kristoff:
That's why Java isn't used in real time systems -yet
among about 100 other reasons.

http://www.rtj.org/
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:20 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2