这句话是什么意思
not safe for concurrent use
意思是?
我在 Android 文档中多次遇到过这个问题。特别是对于 Uri.builder 类:
Helper class for building or manipulating URI references. Not safe for concurrent use.
An absolute hierarchical URI reference follows the pattern: ://?#
Relative URI references (which are always hierarchical) follow one of two patterns: ?# or //?#
An opaque URI follows this pattern: :#
Use buildUpon() to obtain a builder representing an existing URI.
最佳答案
这意味着该类的实例不应同时被多个线程访问。这是因为该类的代码在多线程访问期间没有做任何事情来保护其内部状态 - 例如通过同步其方法或类变量访问。如果您确实想在多个实例之间共享一个实例,那么您需要采取一些措施来调解访问,例如将使用该实例的代码放置在同步方法或代码块中,或者使用某种其他机制(请参阅 java.util.concurrent 包) )。
关于java - 并发使用不安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44486858/