Re: [Java] Synchronized.
> ----- Original Message -----
> From: "Chooti Baba" <
nibm963@...>
> To: "Java Official" <
java_official@yahoogroups.com>
> Subject: [Java] Synchronized.
> Date: Wed, 16 Jul 2008 21:37:08 -0700 (PDT)
>
>
> Hi Gurus,
>
> Please have a look at the following code:
>
>
> public class MsLunch {
> private long c1 = 0;
> private long c2 = 0;
> private Object lock1 = new Object();
> private Object lock2 = new Object();
>
> public void inc1() {
> synchronized(lock1) {
> c1++;
> }
> }
>
> public void inc2() {
> synchronized(lock2) {
> c2++;
> }
> }
> }
>
>
> what is the meaning of the following statements:
> synchronized(lock1)
> synchronized(lock2)
>
>
> I have come across the keyword "synchronized" in blocks/methods,
> but this particular type of "declaration" is confusing me which
> I never came across. Can anyyone please explain me in
> "plain English" the purpose of having a reference within
> brackets next to the keyword "synchronized".
>
>
>
>
>
> Best Regards & Good Luck
>
>
>
> Chooti Baba
>
>
As far as my knowledge is concerned synchronized(lock) performs lock on the lock
object of type Object.lock is of type Object so that it can be referenced in
lieu of any class,synchronized on lock doesn't allows any method that is also
synchronized to access the same object until it has monitor/control of that
locked object.
Base class reference can be assigned to any of its derived class reference so
Locking Object provides synchronisation for any of the classs' objects because
Object class is the base class for any class in Java.Hope it will help u.give
me reply if this is wrong or if u need further clarification.
--
Be Yourself @ mail.com!
Choose From 200+ Email Addresses
Get a Free Account at www.mail.com