Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Andreas Leitgeb Newsgroups: comp.lang.java.programmer Subject: Re: Thread and synchonized question Date: Mon, 30 Sep 2019 10:10:42 -0000 (UTC) Organization: A noiseless patient Spider Lines: 20 Message-ID: References: <55e14769-2ee7-4e11-8f66-69c1b7bf0241@googlegroups.com> Reply-To: avl@logic.at Injection-Date: Mon, 30 Sep 2019 10:10:42 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="57ba0cc4d71e31c6552d95816b111fab"; logging-data="13205"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18QBovOgsGooy2jnWehSrz/" User-Agent: slrn/1.0.3 (Linux) Cancel-Lock: sha1:TnTNkusN820A7qriQ5SN5Rn0PJ8= Xref: csiph.com comp.lang.java.programmer:39164 mike wrote: > We have class A with method synchronized connect(int) that calls > class B that has synchronized connect() (main thread) > I guess the lock will be on class A? There are some relevant details missing, so there are two options: A) either or both of the methods are static, or there are two objects one of A and one of B that you call the method on: then the locks are independent, and main thread just hold both. B) One of the methods is just a superclass method, and both "synchronize"s address the same object, and the main thread holds that one twice. > What if class B and synchronized connect()is called by another > thread ( reconnect thread) I guess lock is on class B. > So does this mean that both main and reconnect threads can access > the synchronized connect() on class B? That can be pretty surely excluded in either of the above cases.