FAQs
Search
Recent Topics
Flagged Topics
Hot Topics
Best Topics
Register / Login
Win a copy of
Securing DevOps
this week in the
Security
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Liutauras Vilda
Bear Bibeault
Devaka Cooray
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Campbell Ritchie
Henry Wong
Saloon Keepers:
Tim Moores
Ron McLeod
salvin francis
Stephan van Hulst
Vijitha Kumara
Bartenders:
Tim Holloway
Carey Brown
Frits Walraven
Forum:
Programmer Certification (OCPJP)
Thread Synchronization
Sujittt Tripathyrr
Ranch Hand
Posts: 96
posted 11 years ago
Hi
Can you please explain me what is the use of synchronized block and please give me a example.
Thanks
Srikanth Basa
Ranch Hand
Posts: 241
posted 11 years ago
I see the question you ask is more generic. Do you mean you need some tutorial or you were facing some issue ?
Gowher Naik
Ranch Hand
Posts: 643
posted 11 years ago
import static java.lang.System.out; class ThreadTest extends Thread{ public void run(){ synchronized(this){ for(int i=0;i<15;i++){ out.println(Thread.currentThread().getName()+i); } } } public static void main(String args[]){ new Thread(new ThreadTest(),"T1: ").start(); new Thread(new ThreadTest(),"T2: ").start(); } }
check code above
It is sorta covered in the
JavaRanch Style Guide
.
Post Reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Teradata ????? does it has scope
ClassLoader problem :ClassCastException
Drop down box not working in IE7 but very well displayed in Mozzila
How to run my own jsp file?
Need your suggestion on ErrorHandling
More...