Tuesday, March 1, 2016

[Java]Thread safe

Thread safe : Data structure can work correctly in the context of multi-threading

Immutable
Immutable object is always thread safe :  after the object is created, it will never change, and there is non possibility for the threads see a different value of it.  
Ex: String, Integer, BigInteger, Double ...
Data structure itself offers the synchronization:
Some class is designed for multi-threading, so its methods are already implemented to trait the synchronization problem : not assure the synchronization, but use fast-fail to tell the programmer there is a problem!
Ex : HashTable, Vector, java.util.concurrent.CopyOnWriteArrayList<E>

Data Structure need synchronization by programmer  
Mono thread is always thread safe, in multi-threading, the
Ex: ArrayList、HashMap、SimpleDateFormat、Connection, ResultSet


No comments:

Post a Comment