Basically, thread-safe can be defined as any method or class that can be able to use multiple threads at the same time without any problems. You can take the below example:
private int myInt = 0;
public int AddOne()
{
int tmp = myInt;
tmp = tmp + 1;
myInt = tmp;
return tmp;
}
I hope this will help.
Want to become a Java Expert? Join Java Certification now!!
Want to know more about Java? Watch this video on Java Tutorial for Beginners | Java Programming: