1. In normal operation, Javadoc does not include the synchronized modifier in its output, and with good reason. The presence of the synchronized modifier in a method declaration is an implementation detail, not a part of its exported API. It does not reliably indicate that a method is thread-safe. The claim that the presence of the synchronized modifier is sufficient to document thread safety embodies the misconception that thread safety is an all-or-nothing property. In fact, there are several levels of thread safety. To enable safe concurrent use, a class must clearly document what level of thread safety it supports.
2. The following list summarizes levels of thread safety:
1) immutable—Instances of this class appear constant. No external synchronization is necessary.
2) unconditionally thread-safe—Instances of this class are mutable, but the class has sufficient internal synchronization that its instances can be used concurrently without the need for any external synchronization.
3) conditionally thread-safe—Like unconditionally thread-safe, except that some methods require external synchronization for safe concurrent use. Examples include the collections returned by the Collections.synchronized wrappers, whose iterators require external synchronization.
4) not thread-safe—Instances of this class are mutable. To use them concurrently, clients must surround each method invocation (or invocation sequence) with external synchronization of the clients’ choosing.
5) thread-hostile—This class is not safe for concurrent use even if all method invocations are surrounded by external synchronization. Thread hostility usually results from modifying static data without synchronization.
3. If an object represents a view on some other object, the client generally must synchronize on the backing object, so as to prevent its direct modification. For example, the documentation for Collections.synchronizedMap says this: It is imperative that the user manually synchronize on the returned map when iterating over any of its collection views:
Map<K, V> m = Collections.synchronizedMap(new HashMap<K, V>()); ... Set<K> s = m.keySet(); // Needn't be in synchronized block ... synchronized(m) { // Synchronizing on m, not s! for (K key : s) key.f(); }
4. If you write an unconditionally thread-safe class, consider using a private lock object in place of synchronized methods. This protects you against synchronization interference by clients and subclasses and gives you the flexibility to adopt a more sophisticated approach to concurrency control in a later release.
5. Every class should clearly document its thread safety properties with a carefully worded prose description or a thread safety annotation. The synchronized modifier plays no part in this documentation. Conditionally thread-safe classes must document which method invocation sequences require external synchronization, and which lock to acquire when executing these sequences.
相关推荐
Item 82: Document thread safety Item 83: Use lazy initialization judiciously Item 84: Don’t depend on the thread scheduler 12 Serialization Item 85: Prefer alternatives to Java serialization Item 86:...
JS:document.all的用法
HeaRtDown: Document Processor for Executable Linear Algebra Papers全文翻译 YONG LI, George Mason University, USA SHOAIB KAMIL, Adobe Research, USA ALEC JACOBSON, University of Toronto and Adobe ...
网页可见区域宽: document.body.clientWidth; 网页可见区域高: document.body.clientHeight; 网页可见区域宽: document.body.offsetWidth (包括边线和滚动条的宽); 网页可见区域高: document.body....
网页可见区域宽: document.body.clientWidth; 网页可见区域高: document.body.clientHeight; 网页可见区域宽: document.body.offsetWidth (包括边线的宽); 网页可见区域高: document.body.offsetHeight (包括...
解决生成pdf文件第一页表头产生红色字体: Evaluation Warning : The document was created with Spire.PDF for Java
该模块将读取HTML并尝试构建XML :: Document( )特征: 如果遇到某些其他标签,则自动关闭某些标签很好地解析脏HTML(AFAIK),如果不正确,则提交错误Perl6的魔力状态: 错误/功能请求维护模式用法: my $...
23.弹出输入提示框:window.prompt();...28.创建一个文档元素:document.createElement(),document.createTextNode() 29.得到元素的方法:document.getElementById() 30.设置表单中所有文本型的成员的值为空:
document_clustering:document_clustering
ReferenceError: document is not defined 本次package.json使用版本信息: { vue-loader: ^15.4.2, mini-css-extract-plugin: ^0.4.3, webpack: ^4.20.2, webpack-cli: ^3.1.2 ... } 相关代码 问题原因: ...
images: document.querySelectorAll('.blurify1'), blur: 1, mode: 'auto', }); new blurify({ images: document.querySelectorAll('.blurify2'), blur: 2, mode: 'auto', }); new blurify({ images: ...
Document document = new Document(); 第二步,为该 Document创建一个 Writer 实例: PdfWriter.getInstance(document, new FileStream("Chap0101.pdf", FileMode.Create)); 第三步,打开当前 Document document...
javascript:document.getElementById('downLoad').action='/download.php?fileid=15775884';downishare('0');javascript:document.getElementById('downLoad').action='/download.php?fileid=15775884';downishare('...
part2 JS Browser Document Event part2 JS Browser Document Event
mongoid_auto_increment:向您的Mongoid :: Document添加一个自动递增字段
:app-root和:document-root选择器,可在路由处于活动状态时将样式应用于根元素。 安装 ember install ember-css-modules-active-route ember-css-modules 这是的插件,因此您也需要安装它。 用法 :app-root :映射...
1.输出语句:document.write("") 2.JS中的注释为:// 3.传统的HTML文档顺序是:document->html->(head,body) 4.一个浏览器窗口中的DOM顺序是:window->(navigator,screen,history,location,document) 5.得到表单中元素的...
第 7 章 漏洞利用207访问 http://www.evil.com/proxy/attack.htm// 设置域为 WebKit 认为的顶级域/*注入框架*
LaTeX: A Document Preparation System 2nd edition part2 货真价实
LaTeX: A Document Preparation System 2nd edition part3 如假包换