Results 1 to 3 of 3
  1. #1
    Jackson86 is offline Member
    Join Date
    Sep 2010
    Rep Power

    Default Can't understand what Joshua Bloch is talking about...

    Hi, folks ! )

    I'm a newby in Java concurrency world. And I can't understand following article
    from 'Effective Java' by Joshua Bloch:

    Chapter 9

    Item 49: Avoid excessive synchronization

    "Invoking an alien method from within a synchronized region can cause failures more severe than deadlocks if the alien method is invoked while the invariants protected by the synchronized region are temporarily invalid. (This cannot happen in the broken work queue example because the queue is in a consistent state when processItem is invoked.) Such failures do not involve the creation of a new thread from within the alien method; they occur when the alien method itself calls back in to the faulty class. Because locks in the Java programming language are recursive, such calls won't deadlock as they would if they were made by another thread. The calling thread already holds the lock, so the thread will succeed when it tries to acquire the lock a second time, even though there is another conceptually unrelated operation in progress on the data protected by the lock. The consequences of such a failure can be catastrophic; in essence, the lock has failed to do its job. Recursive locks simplify the construction of multithreaded object-oriented programs, but they can turn liveness failures into safety failures."

    Every help will be appropriate!

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power


    Joshua meant this:

    Java Code:
    class Alien implements Runnable  {
    	private T t;
    	public Alien(T t) {
    		this.t= t;
    	public void method() {
    	public void run() {
    public class T {
    	public static void main(String[] args) {
    		T t= new T();
    		Alien alien= new Alien(t);
    	public synchronized void sync(Runnable r) {;
    	public synchronized void syncToo() {
    A class T object synchronizes both of its methods on 'this'. An Alien object calls the sync() method which runs the Runnable. Back in Alien it can call another method in T that also attempts to synchronize on 'this' but fails ...

    kind regards,


  3. #3
    Jackson86 is offline Member
    Join Date
    Sep 2010
    Rep Power


    Ok. I understood. Very good example! )

    Thank you very much for your answer and your time.

Similar Threads

  1. understand the code
    By prof.deedee in forum New To Java
    Replies: 8
    Last Post: 11-11-2009, 03:43 AM
  2. I don´t understand
    By Manikyr in forum New To Java
    Replies: 6
    Last Post: 02-23-2009, 12:22 AM
  3. Replies: 0
    Last Post: 12-23-2008, 01:27 PM
  4. Replies: 1
    Last Post: 12-17-2007, 12:13 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