synchronized class

Discussion in 'Java' started by John Goche, Jan 31, 2006.

  1. John Goche

    John Goche Guest

    Hello,

    I would like to know whether the "synchronized class" construct is
    valid in JDK 1.5 and whether it has any meaning at all in the context
    of multithreaded programming or whether the compiler will ignore it
    altogether. I have read some posts stating that "synchronized class"
    is not a legal way to begin a Java class definitions. Any comments
    on this would be sincerely appreciated.

    Thanks,

    JG
    John Goche, Jan 31, 2006
    #1
    1. Advertising

  2. John Goche

    Chris Smith Guest

    John Goche <> wrote:
    > I would like to know whether the "synchronized class" construct is
    > valid in JDK 1.5 and whether it has any meaning at all in the context
    > of multithreaded programming or whether the compiler will ignore it
    > altogether. I have read some posts stating that "synchronized class"
    > is not a legal way to begin a Java class definitions. Any comments
    > on this would be sincerely appreciated.


    Your question is answered in section 8.1.1 of the Java Language
    Specification, third edition. The valid modifiers for a class are any
    annotation, public, protected, private, abstract, static, final, or
    strictfp. It is illegal to place the keyword "synchronized" in front of
    a class.

    --
    www.designacourse.com
    The Easiest Way To Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
    Chris Smith, Jan 31, 2006
    #2
    1. Advertising

  3. John Goche wrote:
    >
    > I would like to know whether the "synchronized class" construct is
    > valid in JDK 1.5 and whether it has any meaning at all in the context
    > of multithreaded programming or whether the compiler will ignore it
    > altogether. I have read some posts stating that "synchronized class"
    > is not a legal way to begin a Java class definitions. Any comments
    > on this would be sincerely appreciated.


    JDK 1.0.2 (not sure about 1.1, certainly not 1.2) allowed "synchronized
    class". That was a bug. IIRC, it set the equivalent but unassigned bit
    in class file. It had, and has still, absolutely no effect on runtime
    behaviour.

    Tom Hawtin
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
    Thomas Hawtin, Jan 31, 2006
    #3
  4. "Thomas Hawtin" <> wrote in message
    news:43dfa14e$0$1491$...
    > John Goche wrote:
    >>
    >> I would like to know whether the "synchronized class" construct is
    >> valid in JDK 1.5 and whether it has any meaning at all in the context
    >> of multithreaded programming or whether the compiler will ignore it
    >> altogether. I have read some posts stating that "synchronized class"
    >> is not a legal way to begin a Java class definitions. Any comments
    >> on this would be sincerely appreciated.

    >
    > JDK 1.0.2 (not sure about 1.1, certainly not 1.2) allowed "synchronized
    > class". That was a bug. IIRC, it set the equivalent but unassigned bit in
    > class file. It had, and has still, absolutely no effect on runtime
    > behaviour.


    It has a huge effect on runtime behavior now: if you can't compile a class,
    it won't run.
    Mike Schilling, Jan 31, 2006
    #4
  5. John Goche

    Adam Maass Guest

    "Mike Schilling" <> wrote:
    > "Thomas Hawtin" <> wrote:
    >> John Goche wrote:
    >>>
    >>> I would like to know whether the "synchronized class" construct is
    >>> valid in JDK 1.5 and whether it has any meaning at all in the context
    >>> of multithreaded programming or whether the compiler will ignore it
    >>> altogether. I have read some posts stating that "synchronized class"
    >>> is not a legal way to begin a Java class definitions. Any comments
    >>> on this would be sincerely appreciated.

    >>
    >> JDK 1.0.2 (not sure about 1.1, certainly not 1.2) allowed "synchronized
    >> class". That was a bug. IIRC, it set the equivalent but unassigned bit in
    >> class file. It had, and has still, absolutely no effect on runtime
    >> behaviour.

    >
    > It has a huge effect on runtime behavior now: if you can't compile a
    > class, it won't run.


    If the .class file has the "synchronized" bit set for the class as a
    whole...

    The point was that early compilers were buggy in allowing ... synchronized
    class .... they set a bit in the .class file. The value of that bit was
    irrelevant to the behavior the class, and still is.

    Modern compilers disallow "synchronized class". But that is a compile-time
    behavior, not a runtime behavior.
    Adam Maass, Feb 1, 2006
    #5
  6. John Goche

    Chris Uppal Guest

    Adam Maass wrote:

    > The point was that early compilers were buggy in allowing ... synchronized
    > class .... they set a bit in the .class file. The value of that bit was
    > irrelevant to the behavior the class, and still is.


    Incidentally, the ACC_SYNCHRONISED bit, 0x0020, has been reinterpreted for
    classes and now signifies the almost indescribably hacky ACC_SUPER flag.
    ACC_SUPER is required (by the JVM spec) to be set for all classes compiled by
    "new" compilers:

    The setting of the ACC_SUPER flag indicates which of two alternative
    semantics for its invokespecial instruction the Java virtual machine is
    to express; the ACC_SUPER flag exists for backward compatibility for
    code compiled by Sun's older compilers for the Java programming language.
    All new implementations of the Java virtual machine should implement
    the semantics for invokespecial documented in this specification. All new
    compilers to the instruction set of the Java virtual machine should set the
    ACC_SUPER flag. Sun's older compilers generated ClassFile flags with
    ACC_SUPER unset. Sun's older Java virtual machine implementations
    ignore the flag if it is set.

    With characteristic imprecision the spec doesn't state which editions of the
    Java platform are required to interpret the flag.

    -- chris
    Chris Uppal, Feb 1, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jerry
    Replies:
    4
    Views:
    131,817
    tonni
    Aug 11, 2010
  2. Pep
    Replies:
    6
    Views:
    29,265
  3. dmcreyno
    Replies:
    9
    Views:
    9,562
    Mark Space
    Jun 27, 2006
  4. ankur
    Replies:
    4
    Views:
    1,436
    Eric Sosman
    Nov 28, 2008
  5. Guillaume dorchies

    How write a synchronized class

    Guillaume dorchies, May 7, 2009, in forum: Ruby
    Replies:
    3
    Views:
    137
    Robert Klemme
    May 7, 2009
Loading...

Share This Page