|
-
Mar 13th, 2002, 04:39 PM
#1
Thread Starter
PowerPoster
Loops and timing in Java...
It's been awhile since I used Java, and I don't think I've got a compilet to test this for myself...
Say I have a set of objects (all derived from the same class) and I need each object to check for some condition every 1 second say, how would I construct this in Java? Can each object run an independant loop, or not, as I guess is the case?
Would I instead need one major loop to go through and make each object check the condition?
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Mar 13th, 2002, 04:46 PM
#2
Addicted Member
Yes, you can do this. Check out threads.
Cudabean
-
Mar 13th, 2002, 04:48 PM
#3
Thread Starter
PowerPoster
Ok, that's good enough for me. I only need to know it to build a design spec for a system (uni project...).
I don't actually have to code it, so that's great.
Cheers.
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Mar 14th, 2002, 01:22 AM
#4
Dazed Member
Without getting into threads in the context
of spawning i would just use the
public static void sleep(long millis)
methods that are defined in the
java.lang.Thread class.
Code:
// process at one second intervals
for(Iterator i = v.iterator(); i.hasNext();){
processObject(i.next());
Thread.sleep(1000);
}
Last edited by Dilenger4; Mar 14th, 2002 at 01:27 AM.
-
Mar 14th, 2002, 04:00 AM
#5
Thread Starter
PowerPoster
Sorry, that was a bit over my head. 
I've just got a major project at uni this semester, and I've got to design a control system for an elevator. Fun stuff...
I don't actually have to code it, just do specs and requirements and stuff, so I just needed an overview, and info on whether Java had multithreading capabilities, which I guess it does, so that's good enough.
Cheers, all.
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|