The Java™ Tutorials — Concurrency :Synchronization 同步
2016-02-11 17:16
477 查看
The Java™ Tutorials — Concurrency :Synchronization 同步
原文地址:https://docs.oracle.com/javase/tutorial/essential/concurrency/sync.html
关键点
同步目的:防止线程冲突以及内存一致性错误线程冲突的两种形式:饥饿与死锁
内存一致性错误:对共享数据的不一致操作
全文翻译
Threads communicate primarily by sharing access to fields and the objects reference fields refer to. This form of communication is extremely efficient, but makes two kinds of errors possible: thread interference and memory consistency errors. The tool neededto prevent these errors is synchronization.
线程主要依靠共享变量以及引用变量所引用的对象进行通信。这样的通信模式虽然高效,但是也会带来两种潜在的问题:线程干扰和内存一致性错误。阻止此错误的工具就是同步。
However, synchronization can introduce thread contention, which occurs when two or more threads try to access the same resource simultaneously and cause the Java runtime to execute one or more threads more slowly, or even suspend their execution. Starvation
and livelock are forms of thread contention. See the section Liveness for more information.
然而,同步可能导致线程冲突。当两个以及两个以上的线程同时尝试获取同种资源时,就会发生线程冲突。同步会引起Java运行时更加缓慢地执行多个线程,甚至会引起执行的阻塞。饥饿和死锁是线程冲突的两种形式。等多信息请参阅《活跃度》章节。
This section covers the following topics:
Thread Interference describes how errors are introduced when multiple threads access shared data.
Memory Consistency Errors describes errors that result from inconsistent views of shared memory.
Synchronized Methods describes a simple idiom that can effectively prevent thread interference and memory consistency errors.
Implicit Locks and Synchronization describes a more general synchronization idiom, and describes how synchronization is based on implicit locks.
Atomic Access talks about the general idea of operations that can’t be interfered with by other threads.
本章节讨论了下面几个话题:
《线程冲突》描述了多个线程获取共享数据时,错误是怎样发送的
《内存一致性错误》描述了对共享数据的不一致访问所引发的后果
《同步方法》描述了一种可以阻止线程冲突和内存一致性错误的傻瓜式方法
《隐式锁和同步》描述了一种更加常见的同步手段,并描述了同步是如何基于隐式锁工作的
《原子操作》描述了对无法被其他线程中断的操作的概述。
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- 使用 Syncthing 在多个设备间同步文件
- PropertyChangeListener简单理解
- c++11 + SDL2 + ffmpeg +OpenAL + java = Android播放器
- 插入排序
- 冒泡排序
- 堆排序