Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #2964
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Eric Sosman <esosman@ieee-dot-org.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Threads and statics |
| Date | Thu, 07 Apr 2011 21:14:49 -0400 |
| Organization | A noiseless patient Spider |
| Lines | 24 |
| Message-ID | <inlnjn$6c1$1@dont-email.me> (permalink) |
| References | <905p9gFpuoU1@mid.individual.net> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Fri, 8 Apr 2011 01:15:35 +0000 (UTC) |
| Injection-Info | mx01.eternal-september.org; posting-host="KiwfXDyOjqGhZBXcfNnZBg"; logging-data="6529"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/f6swNv5XOVfQn0+VFn7pl" |
| User-Agent | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 |
| In-Reply-To | <905p9gFpuoU1@mid.individual.net> |
| Cancel-Lock | sha1:FTd6AspiJxQSfIwJqYtKyr047oQ= |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:2964 |
Show key headers only | View raw
On 4/7/2011 8:34 AM, Dirk Bruere at NeoPax wrote:
> Is there a problem with multiple threads using the same static method of
> a class?
No. There's also no problem with multiple threads using the
same instance method of a class, or even of a particular instance.
What matters is whether the methods use the same data. Static
or instance, it's the data-sharing that requires synchronization or
other special handling -- conversely, it's the non-sharing that
requires no care at all.
Advice that I found illuminating when first learning about
threading: Don't think about the code, think instead about the data
the code manipulates (more generally, about the "state" the code
manipulates). Make sure the data is always seen in a consistent
state, except perhaps by the *one* thread that's in the act of
changing it; then you'll have a correct program. (It might not be
the fastest possible program -- that's where the hard parts come
in -- but at least it won't have race conditions.)
--
Eric Sosman
esosman@ieee-dot-org.invalid
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
Threads and statics Dirk Bruere at NeoPax <dirk.bruere@gmail.com> - 2011-04-07 13:34 +0100
Re: Threads and statics Patricia Shanahan <pats@acm.org> - 2011-04-07 05:41 -0700
Re: Threads and statics Robert Klemme <shortcutter@googlemail.com> - 2011-04-07 07:38 -0700
Re: Threads and statics Lew <lew@lewscanon.com> - 2011-04-07 08:20 -0700
Re: Threads and statics Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-04-07 18:47 -0300
Re: Threads and statics markspace <-@.> - 2011-04-07 09:32 -0700
Re: Threads and statics Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-04-07 21:14 -0400
Re: Threads and statics Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-04-09 18:15 +0200
Re: Threads and statics Lew <noone@lewscanon.com> - 2011-04-09 13:06 -0400
Re: Threads and statics Patricia Shanahan <pats@acm.org> - 2011-04-09 09:29 -0700
Re: Threads and statics Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-04-09 09:29 -0700
Re: Threads and statics Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-04-09 14:57 -0400
Re: Threads and statics "Mike Schilling" <mscottschilling@hotmail.com> - 2011-04-10 23:10 -0700
Re: Threads and statics Tom Anderson <twic@urchin.earth.li> - 2011-04-11 13:25 +0100
Re: Threads and statics Lew <noone@lewscanon.com> - 2011-04-11 08:58 -0400
csiph-web