1. To avoid liveness and safety failures, never cede control to the client within a synchronized method or block. In other words, inside a synchronized region, do not invoke a method that is designed to be overridden, or one provided by a client in the form of a function object. The class has no knowledge of what the method does and has no control over it. Depending on what an alien method does, calling it from a synchronized region can cause exceptions, deadlocks, or data corruption. It is usually not too hard to fix this sort of problem by moving alien method invocations out of synchronized blocks.
2. CopyOnWriteArrayList is a variant of ArrayList in which all write operations are implemented by making a fresh copy of the entire underlying array. Because the internal array is never modified, iteration requires no locking and is very fast.
3. As a rule, you should do as little work as possible inside synchronized regions. Obtain the lock, examine the shared data, transform it as necessary, and drop the lock. If you must perform some time-consuming activity, find a way to move the activity out of the synchronized region.
4. In a multicore world, the real cost of excessive synchronization is not the CPU time spent obtaining locks; it is the lost opportunities for parallelism and the delays imposed by the need to ensure that every core has a consistent view of memory. Another hidden cost of oversynchronization is that it can limit the VM’s ability to optimize code execution.
5. You should make a mutable class thread-safe if it is intended for concurrent use and you can achieve significantly higher concurrency by synchronizing internally than you could by locking the entire object externally. Otherwise, don’t synchronize internally. Let the client synchronize externally where it is appropriate. When in doubt, do not synchronize your class, but document that it is not thread-safe.
6. If a method modifies a static field, you must synchronize access to this field, even if the method is typically used only by a single thread.
相关推荐
Item 79: Avoid excessive synchronization Item 80: Prefer executors, tasks, and streams to threads Item 81: Prefer concurrency utilities to wait and notify Item 82: Document thread safety Item 83: Use ...
解决ORA-00700错误之内存管理和swap空间优化 在Oracle数据库中,ORA-00700错误是指内存不足或swap空间不足,导致数据库无法正常运行。解决此错误需要了解Linux系统的内存管理机制和swap空间的使用情况。...
Detection of Excessive Interrupt Disablement - a new feature which can detect a period of excessive interrupt disablement on a CPU, and create an error log record to report it. This allows you to know...
Excessive 是一个用 Python 开发的 CSS 压缩工具,可拖放任意多的文件并将这些文件合并到一个文件并即时压缩。 标签:Excessive
- **Control Heap Size**: Manage heap size carefully to avoid excessive garbage collection cycles. ###### 2.1.4 Multi-Threading Multi-threading can improve execution speed by allowing concurrent ...
example.rs:6:1: 10:2 warning: Struct contains an excessive number (3) of bools (is_leaving_session, is_connecting, is_doing_stuff). Did you want to create a state machine?, #[warn(excessive_bool_...
the grid under: 1) excessive dc-link voltage 2) excessive ac currents and 3) loss of grid-voltage synchronization. In this paper, the control of single- and two-stage grid-connected VSIs in ...
例如:"Excessive screen time has a detrimental influence upon children's development." 9. **be monotonous and unmotivating**:单调且无法激励人的。如:"Repetitive tasks can make work monotonous and ...
#### 一、WARNING: Route:455-CLKNet: trn_clk_OBUF may have excessive skew because 0 CLK pins and 1 NON_CLK pins failed to route using a CLK template. **警告描述**: 此警告表明在时钟网络中的某些负载...
【船级社】 DNV Criteria for handling of excessive noise and vibration
先来看一张简单的文档树很明显树的顶层节点是NodeA节点,接下来可以通过指定的合适节点移动到树中的任何点,结合以下的代码你可以更好的了解这棵树节点间的相互关系:NodeA.firstChild = NodeA1 NodeA.lastChild = ...
告警名称包括"Sync Reference Excessive Wander"和"Timing Sync Fault",这些告警都是GPS失步的典型表现,直接影响了网络的同步和性能。 问题始于芜湖富贵园小区,该地区的用户报告了上行干扰,导致无法正常上网。...
The extent to which nuclear energy can be a ...and that it should avoid excessive reliance on the business sector and should assume a key role for itself in enhancing trust in nuclear decision-making
- 选项D:'excessive'意为过度的,这里表示过度对健康有害。 5. 下列哪一对词是等级反义词? - 选项B:'big'和'small'表示大小,是等级反义词,因为它们之间存在程度的变化。 6. 她自然地认为一旦有新电影上映,...
Main point: The movement should be gentle, avoid excessive force to prevent eye injury. 5、摩百会穴: Rubbing "Bai Hui" point; (1)体位:施术者坐于受术者头侧;Location: Performer sits at the side of...
例如:alcoholism:excessive drinking of alcohol which becomes addictive(酒精中毒) -ist:one who specializes in,精通于……的人 例如:pharmacologist:a doctor who specializes in the study of drugs...
Avoid excessive logging in performance-critical sections of the code. 6. **Security Considerations:** Ensure that sensitive information is not logged, especially when using logging facilities like ...
过量土壤磷抑制真菌生长的机理研究,为了解决全球因过度使用传统化学肥料导致的真菌生长抑制问题,提供了重要的理论依据和实践意义。本研究由曹志平教授领衔,在中国农业大学资源与环境科学学院生态与生态工程系完成...
Fixed: ListBox code regression in wfxApplication.inc WM_ERASEBKGND handler that caused excessive visual flicker (ControlType.ListBox was accidently set to ControlType.ListView). Fixed: ListView now ...