java concurrency in practice - 1
来源:互联网 发布:cms淘客网站源码 编辑:程序博客网 时间:2024/05/09 15:02
In early timesharing systems, each process was a virtual von Neumann computer; it had a memory space storing both instructions and data, executing instructions sequentially according to the semantics of the machine language, and interacting with the outside world via the operating system through a set of I/O primitives.
Threads allow multiple streams of program control flow to coexist within a process. They share process-wide resources such as memory and file handles, but each thread has its own program counter, stack, and local variables.
multiple threads within the same program can be scheduled simultaneously on multiple CPUs.
Threads are sometimes called lightweight processes, and most modern operating systems treat threads, not processes, as the basic units of scheduling.
Since threads share the memory address space of their owning process, all threads within a process have access to the same variables and allocate objects from the same heap, which allows finer-grained data sharing than inter-process mechanisms. But without explicit synchronization to coordinate access to shared data, a thread may modify variables that another thread is in the middle of using, with unpredictable results.
Timer. Timer is a convenience mechanism for scheduling tasks to run at a later time, either once or periodically. The introduction of aTimer can complicate an otherwise sequential program, because TimerTasks are executed in a thread managed by theTimer, not the application. If a TimerTask accesses data that is also accessed by other application threads, then not only must theTimerTask do so in a thread-safe manner, but so must any other classes that access that data. Oftenthe easiest way to achieve this is to ensure that objects accessed by the TimerTask are themselves thread-safe, thus encapsulating the thread safety within the shared objects.
Remote Method Invocation. RMI lets you invoke methods on objects running in another JVM. When you call a remote method with RMI, the method arguments are packaged (marshaled) into a byte stream and shipped over the network to the remote JVM, where they are unpacked (unmarshaled) and passed to the remote method.
When the RMI code calls your remote object, in what thread does that call happen? You don't know, but it's definitely not in a thread you createdyour object gets called in a thread managed by RMI. How many threads does RMI create? Could the same remote method on the same remote object be called simultaneously in multiple RMI threads?[4]
[4] Answer: yes, but it's not all that clear from the Javadocyou have to read the RMI spec.
A remote object must guard against two thread safety hazards: properly coordinating access to state that may be shared with other objects, and properly coordinating access to the state of the remote object itself (since the same object may be called in multiple threads simultaneously). Like servlets, RMI objects should be prepared for multiple simultaneous calls and must provide their own thread safety.
- java concurrency in practice - 1
- Java Concurrency in Practice
- Java Concurrency in Practice
- Java Concurrency In Practice
- Java Concurrency In Practice Notes
- Java Concurrency in Practice 笔记
- java concurrency in practice - 2
- Understand <Java Concurrency in Practice>
- Java Concurrency in Practice读书笔记
- 《Java Concurrency in Practice》ch5 Building Blocks
- 《Java Concurrency in Practice》ch6 Task Execution
- 《Java Concurrency in Practice》ch9 GUI Applications
- java concurrency in practice读书笔记----第三章
- java concurrency in practice读书笔记---ThreadLocal原理
- 《Java Concurrency in Practice》之线程安全性
- 《Java Concurrency in Practice》之Volatile variables
- 《Java Concurrency in Practice》中文版笔记
- [Java Concurrency in Practice]二至五章小结
- WindowManager$BadTokenException
- 谈谈Unicode编码,简要解释UCS、UTF、BMP、BOM等名词
- 制作cab文件并签名(动态生成infopath模版)
- 去掉sudo的密码
- Android Preference使用
- java concurrency in practice - 1
- AOP与OOP
- mfc 简单的数据运算
- 开张了。
- VS2010打包全过程(图解)
- CRM+SRM
- 功能强大的编辑器——Vi
- android通过httpPost向服务器发送请求
- SQL2000 备份和恢复DTS(本地包)的方法