what is the mean of thread safe ?线程安全是什么意思呢?
【推荐阅读】微服务还能火多久?>>> 一、线程安全是什么意思 As Seth stated thread safe means that a method or class instance can be used by multiple threads at the same time without any problems occuring. Consider the following method: private int myInt = 0;public int AddOne(){ int tmp = myInt; tmp = tmp + 1; myInt = tmp; return tmp;} Now thread A and thread B both would like to execute AddOne(). but A starts first and reads the value of myInt (0) into tmp. Now for some reason the scheduler decides to halt thread A and defer execution to thread B. Thread B now also reads the value of myInt (still 0) into it's own variable