Purpose of making a method thread safe - Java

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.
Can you explain why a constructor doesn't have return type? - Java
The primary goal of a constructor is to create an object. Though the constructor resembles a method, its explicit purpose is to initialize the instance variables.....
Explain how to add a button in applet - Java
The following are the steps to add a button in applet: 1. Declare and create the object of Button class - Button clickMe;....
Explain the purpose of jar file - Java
A Jar file contains mostly .class files and optionally other files like sound files, image files for Java applications, gathered into a single file in the compressed format.....
Post your comment