What Makes a Method Thread-safe? What are the rules?

前端 未结 4 1759
一个人的身影
一个人的身影 2020-11-29 14:52

Are there overall rules/guidelines for what makes a method thread-safe? I understand that there are probably a million one-off situations, but what about in general? Is it t

4条回答
  •  心在旅途
    2020-11-29 15:24

    It must be synchronized, using an object lock, stateless, or immutable.

    link: http://docs.oracle.com/javase/tutorial/essential/concurrency/immutable.html

提交回复
热议问题