The overview of thread safety means that when multiple threads access the same object, if there is no need to consider the scheduling and alternate running of these threads in the runtime environment, there is no need for additional synchronization or any other coordination on the caller. Operations and actions calling this object can obtain correct results. Judging the safety of multi-threading can be analyzed from the following three points:
Your understanding is correct, new MyThread().start() Every time a new Thread object is used to start the thread, there is no sharing behavior, so it is thread-safe, the most voted answer
MyThread mt = new MyThread(); // 这里只 new 了一个对象,然后多线程操作,会存在线程安全问题
new Thread(mt).start();
new Thread(mt).start();
new Thread(mt).start();
// MyRunable mr = new MyRunable();
// new Thread(mr).start();
// new Thread(mr).start();
// new Thread(mr).start();
The overview of thread safety means that when multiple threads access the same object, if there is no need to consider the scheduling and alternate running of these threads in the runtime environment, there is no need for additional synchronization or any other coordination on the caller. Operations and actions calling this object can obtain correct results.
Judging the safety of multi-threading can be analyzed from the following three points:
If multiple threads operate a shared data, thread safety issues must be considered.
The situation you mentioned is definitely thread-safe, because it is only used by your own thread.
Your understanding is correct,
new MyThread().start()
Every time a new Thread object is used to start the thread, there is no sharing behavior, so it is thread-safe, the most voted answerA simple example
If you have a candy that others want to eat, then it is unsafe, so you find that you need a box and a lock to lock it up