File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "threads " Watch "threads " New topic


Mateen Nasir
Ranch Hand

Joined: Aug 01, 2001
Posts: 33
can we have a synchronized intance block or static block
i mean a syn block outside a method
how ?
i have tried and it gives an error
Guoqiao Sun
Ranch Hand

Joined: Jul 18, 2001
Posts: 317
Mateen, seemed we cannot have synchronized instance or static block. We can only synchronize a whole method or part of a method(a block of it).

Guoqiao Sun
Sun Certified Programmer for Java™ 2 Platform
try my mock exam¹²³ at my homepage.

Guoqiao Sun<br />SCJP2 SCWCD2<br />Creator of <a href="" target="_blank" rel="nofollow"></a>, Java resource, mock exam, forum
Ragu Sivaraman
Ranch Hand

Joined: Jul 20, 2001
Posts: 464
Yeah you cant have a synchronized instance or static block
It gives a compile time error
Mateen Nasir
Ranch Hand

Joined: Aug 01, 2001
Posts: 33
Thanks a lot
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Mateen,
You can synchronize on an object using a synchronized block.
See the Sun Tech Tip
Using Synchronized Statements
Hope that helps.

Jane Griscti
Sun Certified Programmer for the Java� 2 Platform

Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
I agree. Here's the link:
subject: threads
Similar Threads
catch and try
problem with download prompt cancel button
Query reg. try catch finally
try catch finally blocks
Question on try catch