zoukankan      html  css  js  c++  java
  • Thread和ThreadGroup

    Thread和ThreadGroup

    学习了:https://www.cnblogs.com/yiwangzhibujian/p/6212104.html  这个里面有Thread的基本内容;

    http://blog.csdn.net/a352193394/article/details/39323427 这个讲解了ThreadGroup

    https://www.cnblogs.com/yy2011/archive/2011/05/05/2037564.html 这个比较了ThreadGroup与Executor

    Thread比如属于一个ThreadGroup,

    源码:

            Thread parent = currentThread();
            SecurityManager security = System.getSecurityManager();
            if (g == null) { // 这个就是ThreadGroup
                /* Determine if it's an applet or not */
    
                /* If there is a security manager, ask the security manager
                   what to do. */
                if (security != null) {
                    g = security.getThreadGroup();
                }
    
                /* If the security doesn't have a strong opinion of the matter
                   use the parent thread group. */
                if (g == null) {
                    g = parent.getThreadGroup();
                }
            }

    Thread.setUncaughtExceptionHandler的意义在于不能修改原线程的情况下,为其增加一个错误处理器。

    package com.stono.thread2;
    
    import java.lang.Thread.UncaughtExceptionHandler;
    
    // UnCaughtException意义在于不能对原线程修改的情况下,为其增加一个错误处理器。
    public class ThreadUncaughtException {
        public static void main(String[] args) {
            Thread t1 = new Thread(new Runnable() {
                public void run() {
                    int a = 1/0;
                }
            });
            t1.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
                @Override
                public void uncaughtException(Thread t, Throwable e) {
                    System.out.println("线程:"+t.getName()+"出现异常,异常信息:"+e);
                    e.printStackTrace();
                }
            });
            t1.start();
        }
    }

    ThreadGroup.enumerate(list)方法把ThreadGroup中的线程拷贝到新的List中;

     在ThreadGroup讲解过程中,一个runnable对象构建了多个线程,这个需要注意一下,TODO

  • 相关阅读:
    automatic preferred max layout width
    UIActivityIndicatorView
    collectionview不能拖动
    消除找不到文件路径的警告
    保存图片到本地和相册
    svn上传.a文件
    UILabel copyWithZone:]: unrecognized selector sent to instance 0x7fd662d8f9b0
    NSString NSURL
    iOS 定位功能
    前端实现左右翻页功能Demo
  • 原文地址:https://www.cnblogs.com/stono/p/8370494.html
Copyright © 2011-2022 走看看