Results 1 to 5 of 5

Thread: Loops and timing in Java...

  1. #1

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205

    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]
    -----------------------------------------

  2. #2
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    Yes, you can do this. Check out threads.

    Cudabean

  3. #3

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    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]
    -----------------------------------------

  4. #4
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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); 
    }

  5. #5

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    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
  •  



Click Here to Expand Forum to Full Width