Purpose of making a method thread safe. How to make a method thread safe without using synchronized keyword?Java supports threads natively without using additional libraries. Using ‘synchronized’ key word makes the methods thread safe. Thread safe methods does not cause another thread to use the same CPU resources without any order, thus ensures congestion. Thread safe ensures / guarantees the threads to use CPU resources one after another.
It is a very good programming standard to use thread safe collections like java.util.Hashtable, java.util.Vector, thread safe class like StringBuffer . Their methods are synchronized.
SingleThreadModel interface also supports making methods thread safe.
Certain collections can be made thread safe by using synchronizedSet(), synchronizedMap(), synchronizedList() and synchronizedCollection() methods.
|