Well, I may have overstated my case: it is not THAT bad, like stop() or 
suspend(), which fully deserve their deprecation, since they are so broken. 
But neither is it that good. If you are using it a lot, it is a strong 
hint, though not a proof, that you are going about something the wrong way. 
For when following the safe-threading practices well established in the 
industry since Birrell, synchronization uses locks/monitors instead of 
directly affecting the scheduler as join() does.

However, the prohibition is not absolute, like the prohibition against 
stop(), destroy() or suspend(), which are officially deprecated, and have 
been for a long time. It is more like a warning that you are probably 
following the wrong idiom, since its best uses are so rare.
 
Code using join() to do synchronization may indeed work. If all your other 
threads really do refrain from accessing state in the waiting thread and 
you have verified with a wait-for-graph that deadlock is impossible, you 
are most likely quite safe -- until somebody modifies your code forgetting 
what made it safe.

However, Birrell included join() in Topaz but then said it was rarely used, 
Berg described it as "used very rarely", and as I already mentioned Goetz 
gave only one example of a concurrency pattern using it.

Finally, there was a very good talk last week at the SF Android Meetup 
given by O'Reilly author Blake Meike on concurrency in Android: his basic 
thesis was that concurrent coding should use as first choice AsyncTask, as 
second choice, Looper/Handler; only when these fail to provide what is 
needed should one even resort to Java's new java.util.concurrent classes. 
Only when truly desperate should one consider going to even lower level 
code, such as Java 1.2 support for concurrency, including join().

Now of course he realizes (as do I) that there are exceptions, when you 
really do need to resort to java 1.2 support bypassing even such handy 
goodies as Executors and concurrent collections (e.g. BlockingQueue). But 
they are not common. Bugs in multithreading code are much more common, 
especially when low level code is used too often.

On Saturday, August 4, 2012 1:21:49 AM UTC-7, Ecthelion wrote:
>
> Can you briefly explain why join() is supposed to be so bad to best almost 
> never use it?

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

Reply via email to