Processes and Threads 进程与线程

Processes and Threads 进程与线程


简述

俗话说的好“纸上得来终觉浅 绝知此事要宫刑”,多线程编程可以最大限度地利用多核心和操作系统的系统,是提高程序运行性能常用的方法!

进程(Process)进程(Thread)也是计算机利于最基本的概念,虽然如此,当我们真正的想开发高效率的并发应用,却发现对于他们的理解还是不够深刻!

在Android中,当app启动时,系统会为这个application启动一个新的Linux进程(单线程执行)。默认情况下,一个应用程序的所有组件都运行相同进程和线程中(我们称之为主线程)。当然,你可以分配应用程序不同的组件到不同的进程中,你可以为任何进程创造额外的的线程。

When an application component(成分) starts and the application does not have any other components running, the Android system starts a new Linux process for the application with a single thread of execution(执行). By default, all components of the same application run in the same process and thread (called the “main” thread). If an application component starts and there already exists a process for that application (because another component from the application exists), then the component is started within that process and uses the same thread of execution. However, you can arrange for different components in your application to run in separate processes, and you can create additional(附加的) threads for any process.


进程-Process

  • 默认情况下,同一个应用程序的所有组件运行在同一个进程下,并且大多数程序不需要改变!

  • 当然你想要控制应用程序组件运行的进程,你可以在清单文件中进行设置。
    清单文件不同的组件元素,如activity , service, receiver, and provider 支持android:process attribute属性,可以指定组件运行在那个进程中!

  • You can set this attribute so that each component runs in its own process or so that some components share a process while others do not. You can also set android:process so that components of different applications run in the same process—provided that the applications share the same Linux user ID and are signed with the same certificates.

进程的生命周期

Andorid系统尽量维持一个应用程序进程,但最后还是需要移除旧进程来回收内存开辟新的进程或者维持重要的进程。为了决定那个进程被保存 那个被移除,Android系统基于进程中运行的组件和组建的状态,为每个

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值