Results 1 to 4 of 4
  1. #1
    flok is offline Member
    Join Date
    Sep 2009
    Location
    Gouda, the Netherlands
    Posts
    24
    Rep Power
    0

    Default Waiting on multiple semaphores at the same time

    Hi,

    Is it possible in Java to wait for multiple semaphores in one call? Like the waitformultipleobjects in win32. So I have multiple semaphores and i would like to be informed if one or more get signalled.

  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    11

    Default

    You could keep looping through the semaphores calling tryAcquire() until you acquire a permit in a particular semaphore? In the loop make it sleep for a 10ms or so as to not burn all the CPU.
    My Hobby Project: LegacyClone

  3. #3
    flok is offline Member
    Join Date
    Sep 2009
    Location
    Gouda, the Netherlands
    Posts
    24
    Rep Power
    0

    Default

    Looping and testing for, say, 10ms would give a latency of (on average) 5ms. I could reduce the sleep-time but then more cpu would be used, slowing other programs down and requirering more power (on e.g. laptops).

  4. #4
    flok is offline Member
    Join Date
    Sep 2009
    Location
    Gouda, the Netherlands
    Posts
    24
    Rep Power
    0

Similar Threads

  1. upload multiple picture at one time
    By chaiwei in forum Java Applets
    Replies: 3
    Last Post: 10-30-2009, 06:39 AM
  2. Make multiple JTextFields focus at the same time.
    By toymachiner62 in forum AWT / Swing
    Replies: 6
    Last Post: 10-09-2009, 03:59 AM
  3. Once again: waiting in a thread loop.
    By willemjav in forum Threads and Synchronization
    Replies: 115
    Last Post: 09-22-2008, 02:35 PM
  4. Waiting for a button to be pressed
    By SomeGuyOverThere in forum New To Java
    Replies: 6
    Last Post: 08-21-2008, 10:30 PM
  5. waiting for a file
    By Fleur in forum New To Java
    Replies: 2
    Last Post: 06-23-2008, 09:18 PM

Posting Permissions

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