JAVA线程——选自《Learn Java for Android Development》
2011-08-23 10:49
381 查看
本文选自《Learn Java for Android Development》中"Thread API"一节。见它对线程的介绍简洁又清晰,自己虽然英语很差,但这一段浅显易懂的文字还是看明白了,就记了下来。
Applications execute via threads, which are independent paths of execution through an application's code. When multiple threads are executing, each thread's path can differ from other thread paths. For example, a thread might execute one of a switch statement's
cases, and another thread might execute another of this statement's cases.
NOTE:Applications use threads to improve performance. Some appications can get by with only the default main thread to carry out their tasks, but other
applications need additional threads to perform time-intensive tasks in the background, so that they remain responsive to their users.
The virtual machine gives each thread its own method-call stack to prevent threads from interfering with each other. Separate stacks let threads keep track of their next instructions to execute, which can fiffer from thread to thread. The stack also provides
a thread with its own copy of method parameters, local variables, and return value.
Java supports thread via its Threading API. This API consists of one interface (Runnable) and four classes(Thread, ThreadGroup, ThreadLocal, and InheritableThreadLocal) int the java.lang package. After exploring Runnable and Thread(and mentioning
ThreadGroup during this exploration), this section explores thread synchronization, ThreadLocal, and InheritableThreadLocal.
NOTE: Java verision 5 introduced the java.util.concurrent package as a high-level alternative to the low-level Threading API. (I will discuss this package in Chapter
9.) Althrough java.util.concurrent is the preferred API for working with threads. you should also be somewhat familiar with Threading because it is helpful in simple threading scenarios. Also, you might have to analyze someone
else's source code that depends on Threading.
Applications execute via threads, which are independent paths of execution through an application's code. When multiple threads are executing, each thread's path can differ from other thread paths. For example, a thread might execute one of a switch statement's
cases, and another thread might execute another of this statement's cases.
NOTE:Applications use threads to improve performance. Some appications can get by with only the default main thread to carry out their tasks, but other
applications need additional threads to perform time-intensive tasks in the background, so that they remain responsive to their users.
The virtual machine gives each thread its own method-call stack to prevent threads from interfering with each other. Separate stacks let threads keep track of their next instructions to execute, which can fiffer from thread to thread. The stack also provides
a thread with its own copy of method parameters, local variables, and return value.
Java supports thread via its Threading API. This API consists of one interface (Runnable) and four classes(Thread, ThreadGroup, ThreadLocal, and InheritableThreadLocal) int the java.lang package. After exploring Runnable and Thread(and mentioning
ThreadGroup during this exploration), this section explores thread synchronization, ThreadLocal, and InheritableThreadLocal.
NOTE: Java verision 5 introduced the java.util.concurrent package as a high-level alternative to the low-level Threading API. (I will discuss this package in Chapter
9.) Althrough java.util.concurrent is the preferred API for working with threads. you should also be somewhat familiar with Threading because it is helpful in simple threading scenarios. Also, you might have to analyze someone
else's source code that depends on Threading.
相关文章推荐
- Learn Java for Android Development (第三版)---简介
- Learn Java for Android Development (第三版)---封面
- 后续_Learn Java for Android Development (第三版)
- 第一章 JAVA入门_Learn Java for Android Development(第三版)
- Development and remote installation of Java service for the Android Devices
- 学习 learning Java for android-Exceptions
- 基于Android2.3.5系统:Java JDK ADT Android SDK for Eclipse环境安装
- 我的Android进阶之旅------>解决:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
- Android项目运行时出现错误: Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for
- Java中运行Shell for Android
- CC++初学者编程教程(10) 搭建Android java C/C++ NDK QTforAndroid 开发环境
- Eclipse For Java&Android 配置
- Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. > com.android.bui
- Cross Platform IDE for Android Native Development
- : java.lang.SecurityException: Unable to find app for caller android.app.ApplicationThreadProxy 解决方法
- 设计模式【一】之策略模式for Java And Android
- Program for Android in C/C++ with the Native Development Kit (if you dare)
- JAVA for android develop
- Setting up PhoneGap on Ubuntu for Android app development
- CC++初学者编程教程(10) 搭建Android java C/C++ NDK QTforAndroid 开发环境