5

Ideally I'd like to add my blocking queue to a selector so I can block reading from a socket or until an item appears on the blocking queue.

Is there some higher level selector-like function that operates on disparate types like these?

I could go the cheesy way out and fire off 2 threads and have each one block individually, but it would be cleaner to have one function that could block on both types of object.

Is there a way to grab the monitor for each object that is being blocked on and use a selector-like object to block on both?

stu
  • 8,461
  • 18
  • 74
  • 112

1 Answers1

2

I don't believe you can have one thread block on both. If the issue is that you have a worker thread that can either accept a task from the queue or directly from a socket, it would probably be cleaner to have a separate thread that reads tasks from the socket and puts them on the queue.

Warren Dew
  • 8,790
  • 3
  • 30
  • 44
  • 1
    It would be cleaner if all things that could block derive from something called BlockingThing. :-) – stu Jun 16 '14 at 20:07