Also, if you ARE modifying the 'status' field later, expecting your other 
thread to have picked up its value, and maybe to have modified it or 
something, you're going to need to do some explicit synchronization, either 
using notify/wait, or some higher-level construction, for example a blocking 
queue.

One common pattern would be to have a single blocking queue, shared between 
all interested threads.

Threads that want something done (say, process a Status() object), push 
their work onto the queue.

The thread that processes it loops, pulling stuff off the queue, and 
processing it.

Since this is a blocking queue, it handles all the synchronization 
internally -- and will block the processing thread when there's no more work 
to be done. You can even have more than one processing thread.

While it's quite possible to handle handoffs of data and control between 
threads using wait()/notify(), it's usually simpler to use a higher-level 
construct. There are certain exact patterns that work with wait/notify, and 
if you learn them, you can use them reliably, but blocking queues and 
similar approaches generally do what you want a lot more simply, and are 
easier to test.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to