Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: A question about synchronized threads Date: Tue, 03 May 2011 18:57:19 -0400 Organization: albasani.net Lines: 45 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; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net FhM0f/nWwlGf+Z6tt2mjm1C31MXd1gCZIObqZVD1N3dfaCmkQKdcU0h1Cc6UGrdjZZIOYlPKUUk8V8cvlZE7FQ== NNTP-Posting-Date: Tue, 3 May 2011 22:56:16 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="YOlqEYs/j2Xa5hc/n1ol76FTZxlPc9x/iWtDW1WUxuMDJNfsIBhLccjUyavxuM08gzo5OoGwYjIhQqdKpqH09SXvsbOPBH9r9JMma+da+J2dTJAU7DxMkvBbT6a7Zeic"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 In-Reply-To: <0f043640-9fb3-430f-bcf6-d830a2dd6e81@k15g2000pri.googlegroups.com> Cancel-Lock: sha1:YwPV/gYLh9M0jCWL5cwxy3veHN0= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3479 byhesed wrote: > I thought that synchronizing entire methods would be wasteful. Why? > Also, although two methods need to be synchronized, > if two methods are totally unrelated to each other, > then it would be too bad, isn't it?\ We cannot tell without an SSCCE. http://sscce.org/ Please provide one. Also, if two methods are "totally unrelated to each other" then you don't need any synchronization at all. They shouldn't even be in the same class, perhaps not even in the same application. > The rate of using CPU resources will be too low. > That is why I though it is ineffectual. How do you know? Please explain your measurement methodology for performance. What was the metric of performance, what value did it have, and how much of overall application performance was it, percentagewise? Make sure that you measure under conditions similar to anticipated real-life loads, and compare proposed "optimizations" to your baseline under the same conditions. Especially with concurrent programming, it is a terrible, terrible mistake to imagine that you will "optimize" something when you don't have any objective data. Much more likely, you will "optimize" by getting wrong answers in half the time of correct ones. 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). You should do ABSOLUTELY NOTHING about or with concurrent programming until you've read at least one of the two books people have recommended to you, and understand it. -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg