synchronized class

J

John Goche

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
 
C

Chris Smith

John Goche said:
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
 
T

Thomas Hawtin

John said:
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
 
M

Mike Schilling

Thomas Hawtin said:
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.
 
A

Adam Maass

Mike Schilling said:
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.
 
C

Chris Uppal

Adam said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top