Java 名为 ThreadSafe 的注解

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19131094/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 14:22:24  来源:igfitidea点击:

Annotation called ThreadSafe

java

提问by Phoenix

@ThreadSafe 
public class A
{
}

Does this annotation actually make the class Thread Safeor is it just for readability?

这个注解实际上使类线程安全还是只是为了可读性?

回答by Maroun

See @ThreadSafe Annotation:

@ThreadSafe注解

Place this annotation on methods that can safely be called from more than one thread concurrently. The method implementer must ensure thread safety using a variety of possible techniquesincluding immutable data, synchronized shared data, or not using any shared data at all.

将此注释放在可以安全地从多个线程并发调用的方法上。方法实现者必须使用各种可能的技术来确保线程安全,包括不可变数据、同步共享数据或根本不使用任何共享数据。

It does not make the class Thread Safe, the programmer does it Thread Safe and adds the annotation.

它不会使类线程安全,程序员将其设为线程安全并添加注释。

You might want to see thishelpful link too.

您可能也想查看这个有用的链接。