当前位置: 首页 > news >正文

联想桥做网站公司建个网站费用多少

联想桥做网站公司,建个网站费用多少,点击网络网站,专业网站设计制作服务Android一个APP里面最少有几个线程 参考 https://www.jianshu.com/p/92bff8d6282f https://www.jianshu.com/p/8a820d93c6aa 线程查看 Android一个进程里面最少包含5个线程,分别为: main线程(主线程)FinalizerDaemon线程 终结者守护线程…

Android一个APP里面最少有几个线程

参考

https://www.jianshu.com/p/92bff8d6282f
https://www.jianshu.com/p/8a820d93c6aa

线程查看

Android一个进程里面最少包含5个线程,分别为:

  1. main线程(主线程)
  2. FinalizerDaemon线程
    终结者守护线程。对于重写了成员函数finalize的对象,它们被GC决定回收时,并没有马上被回收,而是被放入到一个队列中,等待FinalizerDaemon守护线程去调用它们的成员函数finalize,然后再被回收。
  3. FinalizerWatchdogDaemon线程
    监控终结者守护线程。用来监控FinalizerDaemon线程的执行。一旦检测那些重定了成员函数finalize的对象在执行成员函数finalize时超出一定的时候,那么就会退出VM。
  4. HeapTaskDaemon线程
    堆栈守护线程。用来执行堆栈的操作,也就是用来将那些空闲的堆内存归还给系统。
  5. ReferenceQueueDaemon线程。
    引用队列守护线程。我们知道,在创建引用对象的时候,可以关联一个队列。当被引用对象引用的对象被GC回收的时候,被引用对象就会被加入到其创建时关联的队列去。这个加入队列的操作就是由ReferenceQueueDaemon守护线程来完成的。这样应用程序就可以知道哪些被引用对象引用的对象已经被回收了。

下图是创建的一个仅有hello World!页面的工程,线程包含以下的这些。

在这里插入图片描述

刚开始我比较疑惑的是FileObserver 这个线程是否也是每个进程所必须包含的线程。后来我查看了一下Daemons创建的过程,能确定的是Android启动一个APP最少包含ReferenceQueueDaemon线程、FinalizerDaemon线程、FinalizerWatchdogDaemon线程、HeapTaskDaemon线程,以及在ActivityThread中开启的主线程。如下:

public final class Daemons {private static final int NANOS_PER_MILLI = 1000 * 1000;private static final int NANOS_PER_SECOND = NANOS_PER_MILLI * 1000;private static final long MAX_FINALIZE_NANOS = 10L * NANOS_PER_SECOND;public static void start() {ReferenceQueueDaemon.INSTANCE.start();//开启ReferenceQueueDaemon线程FinalizerDaemon.INSTANCE.start();//开启FinalizerDaemon线程FinalizerWatchdogDaemon.INSTANCE.start();//开启FinalizerWatchdogDaemon线程HeapTaskDaemon.INSTANCE.start();//开启HeapTaskDaemon线程}public static void startPostZygoteFork() {ReferenceQueueDaemon.INSTANCE.startPostZygoteFork();FinalizerDaemon.INSTANCE.startPostZygoteFork();FinalizerWatchdogDaemon.INSTANCE.startPostZygoteFork();HeapTaskDaemon.INSTANCE.startPostZygoteFork();}public static void stop() {HeapTaskDaemon.INSTANCE.stop();ReferenceQueueDaemon.INSTANCE.stop();FinalizerDaemon.INSTANCE.stop();FinalizerWatchdogDaemon.INSTANCE.stop();}...
}

1.main线程

2. ReferenceQueueDaemon线程。

代码块

3. FinalizerDaemon线程

    private static class FinalizerDaemon extends Daemon {private static final FinalizerDaemon INSTANCE = new FinalizerDaemon();private final ReferenceQueue<Object> queue = FinalizerReference.queue;private final AtomicInteger progressCounter = new AtomicInteger(0);// Object (not reference!) being finalized. Accesses may race!private Object finalizingObject = null;FinalizerDaemon() {super("FinalizerDaemon");}@Override public void runInternal() {// This loop may be performance critical, since we need to keep up with mutator// generation of finalizable objects.// We minimize the amount of work we do per finalizable object. For example, we avoid// reading the current time here, since that involves a kernel call per object.  We// limit fast path communication with FinalizerWatchDogDaemon to what's unavoidable: A// non-volatile store to communicate the current finalizable object, e.g. for// reporting, and a release store (lazySet) to a counter.// We do stop the  FinalizerWatchDogDaemon if we have nothing to do for a// potentially extended period.  This prevents the device from waking up regularly// during idle times.// Local copy of progressCounter; saves a fence per increment on ARM and MIPS.int localProgressCounter = progressCounter.get();while (isRunning()) {try {// Use non-blocking poll to avoid FinalizerWatchdogDaemon communication// when busy.FinalizerReference<?> finalizingReference = (FinalizerReference<?>)queue.poll();if (finalizingReference != null) {finalizingObject = finalizingReference.get();progressCounter.lazySet(++localProgressCounter);} else {finalizingObject = null;progressCounter.lazySet(++localProgressCounter);// Slow path; block.FinalizerWatchdogDaemon.INSTANCE.goToSleep();finalizingReference = (FinalizerReference<?>)queue.remove();finalizingObject = finalizingReference.get();progressCounter.set(++localProgressCounter);FinalizerWatchdogDaemon.INSTANCE.wakeUp();}doFinalize(finalizingReference);} catch (InterruptedException ignored) {} catch (OutOfMemoryError ignored) {}}}@FindBugsSuppressWarnings("FI_EXPLICIT_INVOCATION")private void doFinalize(FinalizerReference<?> reference) {FinalizerReference.remove(reference);Object object = reference.get();reference.clear();try {object.finalize();} catch (Throwable ex) {// The RI silently swallows these, but Android has always logged.System.logE("Uncaught exception thrown by finalizer", ex);} finally {// Done finalizing, stop holding the object as live.finalizingObject = null;}}}

4. FinalizerWatchdogDaemon线程

代码块

5. HeapTaskDaemon线程

private static class HeapTaskDaemon extends Daemon {private static final HeapTaskDaemon INSTANCE = new HeapTaskDaemon();HeapTaskDaemon() {super("HeapTaskDaemon");}// Overrides the Daemon.interupt method which is called from Daemons.stop.public synchronized void interrupt(Thread thread) {VMRuntime.getRuntime().stopHeapTaskProcessor();}@Override public void runInternal() {synchronized (this) {if (isRunning()) {// Needs to be synchronized or else we there is a race condition where we start// the thread, call stopHeapTaskProcessor before we start the heap task// processor, resulting in a deadlock since startHeapTaskProcessor restarts it// while the other thread is waiting in Daemons.stop().VMRuntime.getRuntime().startHeapTaskProcessor();}}// This runs tasks until we are stopped and there is no more pending task.VMRuntime.getRuntime().runHeapTasks();}}

查看VMRuntime的源码发现 startHeapTaskProcessor()、runHeapTasks()均是native方法。

    public native void requestConcurrentGC();public native void concurrentGC();public native void requestHeapTrim();public native void trimHeap();public native void startHeapTaskProcessor();public native void stopHeapTaskProcessor();public native void runHeapTasks();

如何查看当前项目包含几个线程

在Android studio中点击Profile 图标,点击 CPU,显示如下图,点击 Record,然后再点击 Stop,即可生成。

http://www.hkea.cn/news/305013/

相关文章:

  • 用wordpress制作网站模板沈阳seo
  • 优化一个网站多少钱宜昌网站seo
  • 刚做的网站怎么才能搜索到枸橼酸西地那非片功效效及作用
  • 罗湖区网站公司专业模板建站
  • 哪有备案好的网站国产系统2345
  • 网站开发怎么让别人看到最新营销模式有哪些
  • ssm网站开发源码百度推广多少钱一个月
  • 手游门户网站建设appstore关键词优化
  • 齐河网站开发seo服务内容
  • 北京微信网站建设费用想卖产品怎么推广宣传
  • 网站上线的步骤厦门网站推广公司哪家好
  • 网站做app的软件有哪些百度一下你就知道下载
  • 界面设计的重要性百度seo关键词排名推荐
  • 股票做T网站直播营销
  • 北京手机网站建设公司排名技术优化seo
  • wordpress可爱的主题seo优化教程
  • 自己可以申请网站做外卖吗网站描述和关键词怎么写
  • 公司网站网页设计seo站长工具推广平台
  • 重庆南岸营销型网站建设公司哪家专业真实的网站制作
  • 郑州企业网站建设兼职推广渠道
  • 网站哪些数据优化大师的作用
  • 政府网站集约化建设总结营销软文推广平台
  • 学网站开发跟那个专业最相近百度站长平台注册
  • 网站开发python电脑培训班有哪些科目
  • 惠州响应式网站哪家好云盘搜索
  • spring做网站合肥seo排名收费
  • 做58网站怎么赚钱二十个优化
  • 做企业手机网站北京seo网站开发
  • 关于网站建设中原创文章的一些想法体育热点新闻
  • 天河做网站开发免费留电话号码的广告