Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.21.MISMATCH!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!x8g2000prh.googlegroups.com!not-for-mail From: byhesed Newsgroups: comp.lang.java.programmer Subject: Re: A question about synchronized threads Date: Sat, 30 Apr 2011 09:12:33 -0700 (PDT) Organization: http://groups.google.com Lines: 47 Message-ID: References: <3f249d87-aaf8-4732-9ee8-fd112cf82553@f31g2000pri.googlegroups.com> <8b7289b0-2b52-44f9-96a9-fe1d2661de11@k3g2000prl.googlegroups.com> <922offF2frU1@mid.individual.net> NNTP-Posting-Host: 119.202.36.92 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1304179954 21297 127.0.0.1 (30 Apr 2011 16:12:34 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 30 Apr 2011 16:12:34 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: x8g2000prh.googlegroups.com; posting-host=119.202.36.92; posting-account=v_GC8QoAAABz34PprEBWdejdnnHZvg4_ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.60 Safari/534.24,gzip(gfe) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3379 On 5=EC=9B=941=EC=9D=BC, =EC=98=A4=EC=A0=8412=EC=8B=9C34=EB=B6=84, Robert K= lemme wrote: > On 29.04.2011 18:12, byhesed wrote: > > > On 4=EC=9B=9430=EC=9D=BC, =EC=98=A4=EC=A0=8412=EC=8B=9C53=EB=B6=84, Lew= =C2=A0wrote: > >> What do you mean by "better"? =C2=A0What precisely is not the way you = want it? > >> What is your standard of effectuality? > > If too much spaces are marked as critical regions, > > then the program will not be optimized. > > It wastes too much time in waiting for obtaining a right to access > > critical regions. > > > So, in my question, better means optimization when using threads. > > There is no one size fits all answer to that question. =C2=A0It completel= y > depends on the nature of your application. =C2=A0For example, if read > accesses vastly outnumber write accesses you will get significant > improvements by using read write locks. =C2=A0If it is the other way roun= d > you won't notice a big difference between using "synchronized" and a > read write lock (because most of the time the exclusive write lock will > be used). > > In other situations not sharing mutable state (i.e. copying mutable > state or using immutable state) might be the best solution. =C2=A0Or you = use > a thread safe data structure such as copy on write list. > > There is a whole, big toolbox for writing scalable thread safe > applications. =C2=A0Eric has it exactly right with his suggestion because= the > nature of the state (shared, not shared, mutable, immutable) is the > important aspect to reason about. =C2=A0I recommend reading Doug Lea's > excellent book on the matter. > > Kind regards > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 robert > > -- > remember.guy do |as, often| as.you_can - without endhttp://blog.rubybestp= ractices.com/ Thank you, I'll read it.