>>>>> Christopher Hinds writes:

    Christopher> [1  <multipart/alternative>]
    Christopher> [1.1  <text/plain; us-ascii (7bit)>]
    Christopher> The use of "this" is just plain redundant since
    Christopher> Cliente.class is by default derived from
    Christopher> "java.lang.Object" it is not nessassary to append
    Christopher> "this." to wait() or notify() or any other of the
    Christopher> monitor metheds in this case. Hint : take a look at
    Christopher> the core API class hierarchy.

The use of 'this' is neither redundant nor allowed here -- the 
methods (recibirPeticion() and enviarPeticion()) are static and 
there is no 'this' in class methods. A 'synchronized static' method 
synchronizes on the class object.

// in this example sm1 & sm2 are equivalent and so are m1 & m2
class C
{
        synchronized static void sm1() {}
        static void sm2() { synchronized(C.class) {}}

        static void m1() {}
        void m2() { synchronized(this) {}}
}

You will get compile time errors both for wait() and this.wait() in
static methods. this.waits() fails because there is no this.
wait() fails unless your class has a static method named wait()
[Note: there is no such thing as inheritence for static methods in Java].

The orignal author has several possiblities to fix his code, one
would be to use an explicit lock object , e.g.:

class C
{
        static Object lock = new Object();

        static void m()
        {
                synchronized (lock) {
                        lock.wait();
                }
        }

        static void n()
        {
                synchronized (lock) {
                        lock.notifyAll();
                }
        }
}


        Juergen

-- 
Juergen Kreileder, Universitaet Dortmund, Lehrstuhl Informatik V
Baroper Strasse 301, D-44221 Dortmund, Germany
Phone: ++49 231/755-5806, Fax: ++49 231/755-5802

Reply via email to