简体   繁体   中英

Whether an object can be said thread-safe or not?

如果一个对象在Java中不包含可以更改的实例变量并且没有静态变量,那么它是否可以安全地用Java进行线程安全?

Totally safe, as long as it does not extend a non thread-safe class.

If an object is stateless, it can safely be shared by several threads.

That is also why it is encouraged to use immutable objects in multi-threaded environment as their state cannot be concurrently modified.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM