Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Why "lock" functionality is introduced for all the objects? Date: Wed, 29 Jun 2011 18:56:43 +0200 Lines: 42 Message-ID: <9713qiFldmU1@mid.individual.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net h6GqB4Rxcp2BJP74Fl/XZwAJr9MZxjaeOoalKGR9XnmGS9KDE= Cancel-Lock: sha1:60baXfcbeodI7DjISN1MuIPRxsQ= User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.18) Gecko/20110616 Lightning/1.0b2 Thunderbird/3.1.11 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5776 On 28.06.2011 19:53, Michal Kleczek wrote: > Lew wrote: > >> On 06/28/2011 12:41 PM, Michal Kleczek wrote: >>> Lew wrote: >>> >>>> Alex J wrote: > Yet in the end the community seems to agree not to use "synchronized" > directly but rather use classes from java.util.concurrent (namely Lock and > Condition). So is this keyword really that important? Where do you take that from? I know at least two cases from my recent development history where it came in extremely handy that all objects have a monitor. In those cases where there were a lot of objects stored and we needed to synchronize on each individual object to prevent a bottleneck and allow scalability a solution using an implementation of java.util.concurrent.locks.Lock almost certainly would have used significantly more memory. >> Show me the numbers. What penalty? > > It is (almost) twice as much memory as it could be and twice as much GC > cycles. Almost because in real world the number of objects that you need to > synchronize on is way lower than the number of all objects you create. I'd say that heavily depends on the application type. I don't think such a general statement is warranted. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/