Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #6612
| From | markspace <-@.> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: static synchronized method |
| Date | 2011-07-27 06:37 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <j0p4ag$h3a$1@dont-email.me> (permalink) |
| References | <0e62fc71-0ae6-408c-9e93-c43b3b7c56f0@28g2000pry.googlegroups.com> |
On 7/27/2011 6:31 AM, Ross wrote: > If I have a method which is both static and synchronized, then can I > guarantee that only one thread will be allowed in at once, even if I > have multiple instances of the object in memory, one per thread? Yes. The "synchronized" keyword on a static method synchronizes on the class object. Since all instances of that class share one class object, then there'll be only one thread, period, in that method at a time. There's a slight exception for class loaders which load load multiple instances of the same class object. Since all the static method does is synchronize on the class object, there may be be more than one thread, one per loaded class object, in those circumstances. There are some good reasons to have multiple class objects, but it's not really normal and would usually be considered an error in the class loader, just so you know.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
static synchronized method Ross <rossclement@gmail.com> - 2011-07-27 06:31 -0700
Re: static synchronized method markspace <-@.> - 2011-07-27 06:37 -0700
Re: static synchronized method Henderson <h1@g1.f1> - 2011-07-27 10:47 -0400
Re: static synchronized method lewbloch <lewbloch@gmail.com> - 2011-07-27 14:06 -0700
Re: static synchronized method Alice <quaxx1108@example.com> - 2011-07-27 22:04 -0400
Re: static synchronized method lewbloch <lewbloch@gmail.com> - 2011-07-29 09:28 -0700
Re: static synchronized method Alice <quaxx1108@example.com> - 2011-07-29 18:01 -0400
Re: static synchronized method Ross <rossclement@gmail.com> - 2011-07-28 03:09 -0700
Re: static synchronized method lewbloch <lewbloch@gmail.com> - 2011-07-29 09:29 -0700
Re: static synchronized method Roedy Green <see_website@mindprod.com.invalid> - 2011-07-27 13:43 -0700
csiph-web