esuslogo
 [To advertise Java(tm) Events here, contact joris@esus.com!]
banner

Java™
by example!






New @ Esus.com


  gb  In-house search engine for better results!

  gb  Get updates with the esus.com
newsletter!









  Home 
 Browse Categories 
 Ask a Java Question 
 Help 
  For Java Tips & Tricks, subscribe to the esus.com newsletter!
Search Java Q&A, Links, API's:   adv 

What does it mean for an object or method to be thread-safe?
A thread-safe object means that if several threads access that object simultaneously, that one thread's actions cannot interfere with another's. Threads are run with certain priorities and certain time-slices. A thread can be preempted (interrupted to give another thread control over the CPU) in the middle of its work. An object that is not thread-safe may leave that object in a "corrupted" state. Eg. it may be preempted after writing a row to a database table and before updating a counter variable keeping track of the number of rows. Leaving an object in an inconsistent state may lead to a race condition, a deadlock, or unreliable results.
A possible way to prevent this is to synchronize your methods. This ensures that only one thread can have access to a method at a time and must be completed before another one can execute it. It has its performance implications and the whole threading architecture of your application needs to be carefully examined beforehand.


Further Information
Author of answer: Joris Van den Bogaert

Comments to this answer are only viewable by members. Login or become a member!





Terms of Service | Privacy Policy | Contact

Copyright © 2000-2003 Esus.com - All Rights Reserved 
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. Esus.com is independent of Sun Microsystems, Inc. All other trademarks are the sole property of their respective owners.