• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

threads

 
Mateen Nasir
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
Regards,

------------------
Guoqiao Sun
Sun Certified Programmer for Java™ 2 Platform
try my mock exam¹²³ at my homepage.
 
Ragu Sivaraman
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah you cant have a synchronized instance or static block
It gives a compile time error
 
Mateen Nasir
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic