Results 1 to 4 of 4
  1. #1
    uthred is offline Member
    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    0

    Default What is the right way to wait for a class?

    Hi,

    I have an easy question.
    I have a sensor-class, with a method which give me a dictionary-object. This dictionary is filled by some sensors, which take some time(up to 1 minute) to respond.
    So I have to wait until the dictionary is filled, after it is filled I want the method to respond.
    The aim is it, that a controller initialize the sensor-class, and call every time the method for the dictionary-object, this have to be filled (with at least 8 values).

    But what is the best way to do this?
    I have tried it with a thread, which call the method permanently and check the size of the dictionary, but I think this is the false way.

    I know my English is not the best, but the German forum is closed

    Greetings uthred

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,063
    Rep Power
    8

    Default Re: What is the right way to wait for a class?

    You're not giving any specifics about how all this works so its hard to give any specific advice. I suggest you read through the trail about the Java Concurrency APIs; surely there is one in there that is exactly what you need:

    Lesson: Concurrency (The Java™ Tutorials > Essential Classes)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,044
    Blog Entries
    7
    Rep Power
    23

    Default Re: What is the right way to wait for a class?

    You could model this as a producer/consumer: the thread that needs a filled dictionary is woken up by the tread that filled the dictionary. The dictionary itself is the shared resource.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  4. #4
    uthred is offline Member
    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Replies: 2
    Last Post: 09-25-2011, 05:41 PM
  2. Why wait(), notify(), notifyAll() declared in Object class?
    By Rituparna in forum Threads and Synchronization
    Replies: 2
    Last Post: 04-24-2011, 12:46 AM
  3. wait() and notify()
    By jomypgeorge in forum New To Java
    Replies: 4
    Last Post: 02-15-2011, 09:58 AM
  4. Why would a String class need a wait() method?
    By javanb in forum New To Java
    Replies: 8
    Last Post: 12-06-2010, 02:36 PM
  5. How to use sleep() to wait for a while
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-09-2008, 06:32 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •