Java线程基础知识
来源:互联网 发布:网络主播经纪公司 编辑:程序博客网 时间:2024/05/02 12:54
http://tutorials.jenkov.com/java-concurrency/index.html
Java Concurrency / Multithreading Tutorial
- Multithreading and Concurrency in Java
- Java Concurrency in 2015 and Forward
Back in the old days a computer had a single CPU, and was only capable of executing a single program at a time. Later came multitasking which meant that computers could execute multiple programs (AKA tasks or processes) at the same time. It wasn't really "at the same time" though. The single CPU was shared between the programs. The operating system would switch between the programs running, executing each of them for a little while before switching.
Along with multitasking came new challenges for software developers. Programs can no longer assume to have all the CPU time available, nor all memory or any other computer resources. A "good citizen" program should release all resources it is no longer using, so other programs can use them.
Later yet came multithreading which mean that you could have multiple threads of execution inside the same program. A thread of execution can be thought of as a CPU executing the program. When you have multiple threads executing the same program, it is like having multiple CPUs execute within the same program.
Multithreading can be a great way to increase the performance of some types of programs. However, mulithreading is even more challenging than multitasking. The threads are executing within the same program and are hence reading and writing the same memory simultanously. This can result in errors not seen in a singlethreaded program. Some of these errors may not be seen on single CPU machines, because two threads never really execute "simultanously". Modern computers, though, come with multi core CPUs, and even with multiple CPUs too. This means that separate threads can be executed by separate cores or CPUs simultanously.
If a thread reads a memory location while another thread writes to it, what value will the first thread end up reading? The old value? The value written by the second thread? Or a value that is a mix between the two? Or, if two threads are writing to the same memory location simultanously, what value will be left when they are done? The value written by the first thread? The value written by the second thread? Or a mix of the two values written?
Without proper precautions any of these outcomes are possible. The behaviour would not even be predictable. The outcome could change from time to time. Therefore it is important as a developer to know how to take the right precautions - meaning learning to control how threads access shared resources like memory, files, databases etc. That is one of the topics this Java concurrency tutorial addresses.
Multithreading and Concurrency in Java
Java was one of the first languages to make multithreading easily available to developers. Java had multithreading capabilities from the very beginning. Therefore, Java developers often face the problems described above. That is the reason I am writing this trail on Java concurrency. As notes to myself, and any fellow Java developer whom may benefit from it.
The trail will primarily be concerned with multithreading in Java, but some of the problems occurring in multithreading are similar to problems occurring in multitasking and in distributed systems. References to multitasking and distributed systems may therefore occur in this trail too. Hence the word "concurrency" rather than "multithreading".
Java Concurrency in 2015 and Forward
A lot has happened in the world of concurrent architecture and design since the first Java concurrency books were written, and even since the Java 5 concurrency utilities were released.
New, asynchronous "shared-nothing" platforms and APIs like Vert.x and Play / Akka and Qbit have emerged. These platforms use a different concurrency model than the standard Java / JEE concurrency model of threading, shared memory and locking. New non-blocking concurrency algorithms have been published, and new non-blocking tools like the LMax Disrupter have been added to our toolkits. New functional programming parallelism has been introduced with the Fork and Join framework in Java 7, and the collection streams API in Java 8.
With all these new developments it is about time that I updated this Java Concurrency tutorial. Therefore, this tutorial is once againwork in progress. New tutorials will be published whenever time is available to write them.
- java基础知识(线程方面)
- java线程安全-基础知识
- java 线程基础知识
- java线程基础知识
- java线程基础知识总结
- java线程基础知识
- Java线程基础知识
- Java线程基础知识
- java 线程基础知识
- Java线程基础知识
- java线程的基础知识
- java线程基础知识
- java线程基础知识
- java线程基础知识
- Java笔记 - 线程基础知识
- java线程基础知识
- java线程池基础知识
- Java基础知识回顾--线程
- IOS学习 隐藏status bar的设置
- python book 学习笔记(六)
- Android异步任务
- JS在IE和FF下不兼容的问题及部分解决办法
- 异步分页加载
- Java线程基础知识
- 关于gcc、glibc和binutils的关系
- How to completely uninstall mysql in ubuntu
- <数据结构学习与实验指导>2-5求集合数据的均方差
- 武汉调查公司建议不管发生什么请理性对待
- sql 时间函数基础
- Google Protocol Buffer 的使用和原理
- 动态缓存技术之CSI,SSI,ESI
- android 音频资料