Synchronized objects

Apologize if it's a too basic questoin

I have a class A with two synchronized methods 1 and 2.

Now class B access Class A's method 1

Class C access Class A's method 2

In this case, whether this two threads can have access on Class A object

Thanks in advance

[299 byte] By [_AM__a] at [2007-11-27 11:10:37]
# 1

http://www.cs.brown.edu/courses/cs015/ref/javarefguide/synchronized.html

The object instance can be accessed by only one thread at a time.

DikkeDouwea at 2007-7-29 13:42:51 > top of Java-index,Core,Core APIs...
# 2

> The object instance can be accessed by only one

> thread at a time.

Incorrect.

Synchronization does not prevent "accessing an instance." It prevents obtaining a lock.

jverda at 2007-7-29 13:42:51 > top of Java-index,Core,Core APIs...
# 3

> Apologize if it's a too basic questoin

>

> I have a class A with two synchronized methods 1 and

> 2.

>

> Now class B access Class A's method 1

> Class C access Class A's method 2

>

> In this case, whether this two threads can have

> access on Class A object

>

If both B and C are trying to call methods on the same instance of A, then while B is executing method 1, C will be blocked from entering method 2.

jverda at 2007-7-29 13:42:51 > top of Java-index,Core,Core APIs...
# 4

> > The object instance can be accessed by only one

> > thread at a time.

>

> Incorrect.

>

> Synchronization does not prevent "accessing an

> instance." It prevents obtaining a lock.

Incorrect.

Synchronization does not prevents obtaining a lock instead it delays obtaining a lock (in the end the method will get the lock ... by preventing something it means it will never occur http://www.fhch.org/ncv/dic/prevent.html). I can admit my formulation was flawed, but so is yours.

DikkeDouwea at 2007-7-29 13:42:51 > top of Java-index,Core,Core APIs...
# 5

> > > The object instance can be accessed by only one

> > > thread at a time.

> >

> > Incorrect.

> >

> > Synchronization does not prevent "accessing an

> > instance." It prevents obtaining a lock.

>

> Incorrect.

>

> Synchronization does not prevents obtaining a lock

> instead it delays obtaining a lock (in the end the

> method will get the lock ... by preventing something

Yes, delay is more accurate than prevent. However "prevent obtaining a lock" is still more accurate than what you originally stated.

> it means it will never occur

I disagree.

http://mw1.merriam-webster.com/dictionary/prevent

3: to keep from happening or existing <steps to prevent war>

4: to hold or keep back : hinder, stop often used with from

intransitive verb

: to interpose an obstacle

Nothing there implies "never".

> http://www.fhch.org/ncv/dic/prevent.html).

verb: keep from happening or arising

Doesn't necessarily mean never.

> I can

> admit my formulation was flawed, but so is yours.

You had the mechanics wrong. I merely wasn't as precise as I should've been. "Temporarily prevent" would have been better, but "prevent" isn't wrong, just unclear.

jverda at 2007-7-29 13:42:51 > top of Java-index,Core,Core APIs...