本文选自《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.


更多相关文章

  1. GPS 研究(Android2.3)
  2. 知识梳理系列之五——OkHttp的原理
  3. [置顶] [Android基础]Android中使用HttpURLConnection
  4. android之Handler的使用,回到主线程更新UI的四种方法
  5. 面试题总结(2018.7.26开始,持续更新中)
  6. Android(安卓)开发之 View.post() 的作用
  7. Android(安卓)JNI回调
  8. Android(安卓)线程池
  9. Android保持屏幕常亮唤醒状态的方法

随机推荐

  1. Android开发SQLite基本用法
  2. Android(安卓)当子控件设置 focusable=tr
  3. APP完全退出
  4. Android(安卓)ConstraintLayout 两控件部
  5. android 9.0 Intent卸载应用无反应问题
  6. Android(安卓)Monitor使用介绍
  7. android bluetooth开发基础-9管理连接
  8. Android(安卓)使用Gson解析json用法
  9. Android布局之线性布局——LinearLayout
  10. android 处理txt文件类FileUtils,利用java