Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #2424

Re: Safety Of Non-Synchronized Collections

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From markspace <markspace@nospam.nospam>
Newsgroups comp.lang.java.help
Subject Re: Safety Of Non-Synchronized Collections
Date Wed, 09 Jan 2013 16:50:15 -0800
Organization A noiseless patient Spider
Lines 30
Message-ID <kcl38a$kd3$1@dont-email.me> (permalink)
References <kbvhvc$le1$1@dont-email.me> <g23be8tkcm1sh99m4030ggvr9vesj6fj4r@4ax.com> <e1ce2d29-dca1-4364-8cd3-5512dd0694c5@googlegroups.com> <msjre89stl98m7qo7amclqm7flhbe2q3n8@4ax.com> <772d9033-e4a4-467b-8957-6b9d13f5b32c@googlegroups.com> <T0lHs.46118$On7.4342@newsfe16.iad> <545e86d1-22b5-42bf-b56f-7c03ac186706@googlegroups.com> <2ZmHs.43434$Sl.37958@newsfe27.iad> <85f704a2-b524-4dc0-abf8-83250d55cc18@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Thu, 10 Jan 2013 00:50:18 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="61282af8d6595e8d991edb5ac03d6e00"; logging-data="20899"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18mJ3AQojPG8HzIT4UsJBfoKpz+RZtdLMM="
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2
In-Reply-To <85f704a2-b524-4dc0-abf8-83250d55cc18@googlegroups.com>
Cancel-Lock sha1:aKVNJjaJDxyAXg+ssOdFWf2uXoc=
Xref csiph.com comp.lang.java.help:2424

Show key headers only | View raw


On 1/9/2013 4:26 PM, Lew wrote:
>
> http://rayfd.me/2007/11/11/when-a-synchronized-class-isnt-threadsafe/
>
> This is elementary concurrency gotcha lore.
>

Note this sentence from the article: "Changing the synchronized List to 
Vector doesn't help either."

Vector is thread safe.  Objects wrapped by Collections.synchronized() 
are thread safe.  This does not guarantee that every use of those 
classes is safe, or correct.

Their example is of a single collection which is accessed by multiple 
threads.  As they show their example produces errors.  This is an issue 
of atomicity, not thread safety.  The single collection is still 
perfectly safe, in spite of the errors.  There are no data races. 
However, the program produces errors because it is poorly designed.  It 
requires atomicity, and synchronized methods don't provide that across 
multiple method calls.

So the problem is really one of quibbling over terminology.  Thread 
safety and atomicity both fall under the more general heading of 
concurrency and concurrent programming.  Thread safety and atomicity are 
not the same thing.  They overlap a bit, but not much, so it's best to 
actually understand what is being discussed.  In Java, thread safe means 
an absence of data races, but that's all.  It says nothing about 
atomicity, or the correctness of any given program.

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Safety Of Non-Synchronized Collections Steve <tinker123@gmail.com> - 2013-01-01 15:46 -0500
  Re: Safety Of Non-Synchronized Collections Knute Johnson <nospam@knutejohnson.com> - 2013-01-01 14:18 -0800
    Re: Safety Of Non-Synchronized Collections Lew <lewbloch@gmail.com> - 2013-01-01 15:43 -0800
  Re: Safety Of Non-Synchronized Collections markspace <markspace@nospam.nospam> - 2013-01-01 16:17 -0800
    Re: Safety Of Non-Synchronized Collections Lew <lewbloch@gmail.com> - 2013-01-02 11:12 -0800
      Re: Safety Of Non-Synchronized Collections markspace <markspace@nospam.nospam> - 2013-01-02 12:56 -0800
        Re: Safety Of Non-Synchronized Collections Lew <lewbloch@gmail.com> - 2013-01-02 17:46 -0800
  Re: Safety Of Non-Synchronized Collections Roedy Green <see_website@mindprod.com.invalid> - 2013-01-03 05:59 -0800
    Re: Safety Of Non-Synchronized Collections Lew <lewbloch@gmail.com> - 2013-01-03 15:30 -0800
      Re: Safety Of Non-Synchronized Collections Roedy Green <see_website@mindprod.com.invalid> - 2013-01-09 12:17 -0800
        Re: Safety Of Non-Synchronized Collections Lew <lewbloch@gmail.com> - 2013-01-09 12:56 -0800
          Re: Safety Of Non-Synchronized Collections Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-01-09 13:10 -0800
            Re: Safety Of Non-Synchronized Collections Lew <lewbloch@gmail.com> - 2013-01-09 14:51 -0800
              Re: Safety Of Non-Synchronized Collections Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-01-09 15:22 -0800
                Re: Safety Of Non-Synchronized Collections Lew <lewbloch@gmail.com> - 2013-01-09 16:26 -0800
                Re: Safety Of Non-Synchronized Collections Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-01-09 16:42 -0800
                Re: Safety Of Non-Synchronized Collections Lew <lewbloch@gmail.com> - 2013-01-09 16:54 -0800
                Re: Safety Of Non-Synchronized Collections Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-01-10 10:30 -0800
                Re: Safety Of Non-Synchronized Collections Lew <lewbloch@gmail.com> - 2013-01-10 10:58 -0800
                Re: Safety Of Non-Synchronized Collections markspace <markspace@nospam.nospam> - 2013-01-09 16:50 -0800
                Re: Safety Of Non-Synchronized Collections Lew <lewbloch@gmail.com> - 2013-01-09 16:59 -0800
                Re: Safety Of Non-Synchronized Collections markspace <markspace@nospam.nospam> - 2013-01-10 08:18 -0800
                Re: Safety Of Non-Synchronized Collections Lew <lewbloch@gmail.com> - 2013-01-10 10:49 -0800
                Re: Safety Of Non-Synchronized Collections Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2013-01-10 13:37 +0200
                Re: Safety Of Non-Synchronized Collections Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-01-10 09:27 -0500
                Re: Safety Of Non-Synchronized Collections Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2013-01-10 17:14 +0200
                Re: Safety Of Non-Synchronized Collections Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-01-10 11:44 -0500
                Re: Safety Of Non-Synchronized Collections Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2013-01-10 23:41 +0200
                Re: Safety Of Non-Synchronized Collections Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-01-10 17:14 -0500
                Re: Safety Of Non-Synchronized Collections Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2013-01-11 09:10 +0200
                Re: Safety Of Non-Synchronized Collections Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-01-11 08:25 -0500

csiph-web