Previously learned Thread-safe Classes:
Stringbuffer: A variable sequence of characters for thread Safety. A String
string buffer that is similar to, but cannot be modified.
Vector: Vector
classes can implement an array of objects that can grow.
Hashtable: This class implements a hash table that maps the keys to the corresponding Values. Any non- null
object can be used as a key or a Value.
1 // Thread-safe Classes 2 New StringBuffer (); 3 New vector<string>(); 4 New hashtable<string, string> ();
As mentioned before, vector is a thread-safe time to consider, but even if it is safe, do not use it.
so, What do we use? Use the Following:
API Search Collections, viewing methods
A:public static <T> Collection<T> synchronizedcollection(Collection<t > c): Returns the synchronization (thread-safe) collection that the specified collection Supports.
B:public static <T> list<T> synchronizedlist(list<T> list) : Returns a list of synchronized (thread-safe) support for the specified List.
C:public static <K,V> map<K,V> synchronizedmap(map<K,V> M) : Returns the synchronous (thread-safe) mappings supported by the specified mappings.
D:public static <T> set<T> synchronizedset(set<T> s): returns the specified set Supported Synchronous (thread-safe) Set.
E:public static <K,V> sortedmap<K,V> synchronizedsortedmap(sortedmap <K,V> m): Returns a synchronous (thread-safe) ordered map supported by the specified ordered MAP.
F:public static <T> SortedSet<T> synchronizedsortedset(SortedSet<T> S) : Returns a synchronous (thread-safe) ordered set supported by the specified ordered Set.
Choose b as an example:
The previous thread is not secure:
New Arraylist<string> (); // Thread not secure
Now use b, thread-safe:
List<string> List2 = collections.synchronizedlist (new// thread safe
Pre-java Security Class review, and what classes to use later when thread safety is required