西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 8 Multi-threading

Android Programming Lecture 8 Multi-threading
Android Programming Lecture 8 Multi-threading

Timesharing Operating Systems All modern operating systems are capable of sharing processor(s)between multiple users and processes o Process scheduling algorithms There are often lots (hundreds)of processes running o Many are managed by the system o Some are user executed Adobe
Timesharing Operating Systems • All modern operating systems are capable of sharing processor(s) between multiple users and processes o Process scheduling algorithms • There are often lots (hundreds) of processes running o Many are managed by the system o Some are user executed 2

Process A process is typically defined as execution of a single program on a computing device o Processes are scheduled by the OS o Processes are owned by a user or the OS(root) o Processes may have a long lifetime (a web server)or a short lifetime(one run of a short program) o Processes do not share memory between each other o Most OS support inter-process communication 路
Process • A process is typically defined as execution of a single program on a computing device o Processes are scheduled by the OS o Processes are owned by a user or the OS (root) o Processes may have a long lifetime (a web server) or a short lifetime (one run of a short program) o Processes do not share memory between each other o Most OS support inter-process communication 3

Threads A thread is a component of a process o Usually considered the smallest unit that can be scheduled by an OS o Can share memory and instructions with other threads in the same process o Most OS support inter-thread communication
Threads • A thread is a component of a process o Usually considered the smallest unit that can be scheduled by an OS o Can share memory and instructions with other threads in the same process o Most OS support inter-thread communication 4

Process V.S.Thread Differenco betwveen process+ad one tread of contol 众Second https://www.youtube.com/watch?v=O3EyzlZxx3g
Process V.S. Thread https://www.youtube.com/watch?v=O3EyzlZxx3g 5

Timesharing Operating Systems On a single processor system, o"Round robin"scheduling system switches between threads and processes fast enough that it appears that multiple programs are running o Only one is every truly executing at a time On multi-core or multi-processor systems, o Threads or processes can be allocated across the processors True parallel processing o“Round-robin”scheduling still occurs 6
Timesharing Operating Systems • On a single processor system, o “Round robin” scheduling system switches between threads and processes fast enough that it appears that multiple programs are running o Only one is every truly executing at a time • On multi-core or multi-processor systems, o Threads or processes can be allocated across the processors ▪ True parallel processing o “Round-robin” scheduling still occurs 6

Android Android starts a new Linux process for the application with a single thread of execution All components of the same application run in the same process and thread 。This thread is called the“main”thread or“U"thread Any updates to the Ul/display must be accomplished on the main thread
Android • Android starts a new Linux process for the application with a single thread of execution • All components of the same application run in the same process and thread • This thread is called the “main” thread or “UI” thread • Any updates to the UI/display must be accomplished on the main thread 7

Slow Android App If a component of the work takes a long time,the rest of the work will be“blocked" For example,a long time to access data across the network prevents responding to any GUl events In the Android OS,if a GUl doesn't respond to an input event in five seconds,then it is considered unresponsive and the OS will try to kill it赳 SimpleApp is not responding. Would you like to close it? wal OK 6
Slow Android App • If a component of the work takes a long time, the rest of the work will be “blocked” • For example, a long time to access data across the network prevents responding to any GUI events • In the Android OS, if a GUI doesn’t respond to an input event in < five seconds, then it is considered unresponsive and the OS will try to kill it! 8

Multi-threading 。Put non-Ul work on a Android App separate thread UI For example,download an Main Thread image,connect to a remote server,open a web browser... Java Threads BG BG BG Background Thread 9
Multi-threading • Put non-UI work on a separate thread • For example, download an image, connect to a remote server, open a web browser… 9 UI Android App Java Threads BG BG BG Main Thread Background Thread

Android App What technique shall I use for my background thread Java Threads execution? BG BG Linux Process BG Application Application Time Start End 10
10 Application Start Application End Linux Process BG Time UI UI Android App Java Threads BG BG BG What technique shall I use for my background thread execution?
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 7 Data Persistence.pptx
- 西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 6 List View and Custom View.pptx
- 西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 5 Intent.pptx
- 西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 4 Activity, Intent and UI.pptx
- 西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 3 File structure and Layout.pptx
- 西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 2 Introduction to Java and Object Oriented Programming.pptx
- 西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 1 Introduction to Network Computing(主讲:栾浩).pptx
- 《算法基础》课程教学资源(学习笔记)算法基础 课堂笔记.pdf
- 长沙理工大学:《微机原理与接口技术》课程教学资源(大纲教案)微机原理与应用授课教案(负责人:叶青,打印版).pdf
- 同济大学:《逻辑网络》课程电子教案(PPT课件)数字设计中的基本电路 Introduction to the circuits in digital design.ppt
- 同济大学:《逻辑网络》课程电子教案(PPT课件)异步时序电路分析与设计 Introduction to asynchronous circuits design.ppt
- 同济大学:《逻辑网络》课程电子教案(PPT课件)寄存器与计数器 register and counters.ppt
- 同济大学:《逻辑网络》课程电子教案(PPT课件)同步时序电路设计中的问题 Advanced design issue.ppt
- 同济大学:《逻辑网络》课程教学资源(试卷习题)考试样卷.doc
- 同济大学:《逻辑网络》课程教学资源(教学大纲)逻辑网络(英文)Logic networks.doc
- 同济大学:《逻辑网络》课程教学资源(教学大纲)逻辑网络(中文,负责人:周俊鹤).doc
- 北京化工大学:《数据结构》课程PPT教学课件(C语言描述)第六章 查找.ppt
- 北京化工大学:《数据结构》课程PPT教学课件(C语言描述)第五章 图.ppt
- 北京化工大学:《数据结构》课程PPT教学课件(C语言描述)第三章 栈和队列.ppt
- 北京化工大学:《数据结构》课程PPT教学课件(C语言描述)第二章 线性表.ppt
- 西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 9 Service and Broadcast Receiver.pptx
- 西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 10 Multimedia.pptx
- 同济大学:《软件测试》课程电子教案(PPT课件)Chapter 01 Soft Testing - Fundamentals of Testing.pptx
- 同济大学:《软件测试》课程电子教案(PPT课件)Chapter 02 Testing throughout the Software Lifecycle.pptx
- 同济大学:《软件测试》课程电子教案(PPT课件)Chapter 03 Static Techniques.pptx
- 同济大学:《软件测试》课程电子教案(PPT课件)Chapter 04 Test Design Techniques.pptx
- 同济大学:《软件测试》课程电子教案(PPT课件)Chapter 05 Test Management.pptx
- 同济大学:《软件测试》课程电子教案(PPT课件)Chapter 06 Tool Support for Testing.pptx
- 同济大学:《软件测试》课程电子教案(PPT课件)How To Do High Quality Research, Write Acceptable Papers, and Make Effective Presentations?.ppt
- 《软件测试》课程电子教案(参考资料)Standard glossary of terms used in Software Testing(Version 2.0).pdf
- 《软件测试》课程电子教案(参考资料)Certified Tester Foundation Level Syllabus Released(Version 2011).pdf
- 《软件测试》课程电子教案(参考资料)Certified Tester Foundation Level Syllabus Released(Version 2011).pdf
- 河南科技大学:信息工程学院教育技术学专业本科课程教学大纲(汇编).pdf
- 吉林大学:《人工智能》课程电子教案(PPT课件)第一章 绪论 Artificial Intelligence(AI).ppt
- 吉林大学:《人工智能》课程电子教案(PPT课件)第七章 机器学习.ppt
- 吉林大学:《人工智能》课程电子教案(PPT课件)第三章 知识与知识表示.ppt
- 吉林大学:《人工智能》课程电子教案(PPT课件)第二章 人工智能的数学基础.ppt
- 吉林大学:《人工智能》课程电子教案(PPT课件)第五章 搜索策略.ppt
- 吉林大学:《人工智能》课程电子教案(PPT课件)第八章 智能决策支持系统.ppt
- 吉林大学:《人工智能》课程电子教案(PPT课件)第六章 专家系统.ppt