Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!goblin1!goblin2!goblin.stu.neva.ru!feeder.erje.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Deeyana Newsgroups: comp.lang.java.programmer Subject: Re: A question about synchronized threads Date: Wed, 4 May 2011 00:17:06 +0000 (UTC) Organization: A noiseless patient Spider Lines: 25 Message-ID: References: <3f249d87-aaf8-4732-9ee8-fd112cf82553@f31g2000pri.googlegroups.com> <68sr88-fuj.ln1@dagon.net> <0f043640-9fb3-430f-bcf6-d830a2dd6e81@k15g2000pri.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Wed, 4 May 2011 00:17:06 +0000 (UTC) Injection-Info: mx03.eternal-september.org; posting-host="in7ZCYFYr/2BrjQF4+4MLQ"; logging-data="13766"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/TFXFxBmjs4wqY3CywFlRGaurVQtRhOuY=" User-Agent: XanaNews/1.18.1.6 Cancel-Lock: sha1:Ipz17SXK137wBJ8M+ip3uPEFHEE= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3481 On Tue, 03 May 2011 18:57:19 -0400, Lew wrote: > byhesed wrote: >> I thought that synchronizing entire methods would be wasteful. > > Why? It is well known that shorter critical sections and finer lock granularity can increase concurrency, Lew. > Also, if two methods are "totally unrelated to each other" then you > don't need any synchronization at all. Classic unsubstantiated and erroneous claim. They may still need synchronization to prevent the simultaneous use of a) the SAME one by two different threads on the same object or b) one of them and some third method on the same object. But you may want an explicit lock object instead of the default effects of declaring the methods synchronized. > The single best, most effective way to optimize concurrent code is not > to share data. The second-best way is to make shared-data immutable > (read-only). Clojure can help a lot with the latter.