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

  • 相关阅读:
    机器学习系列丛书
    Growing Pains for Deep Learning
    What qualities characterize a great PhD student
    PHP中$_SERVER的具体參数与说明
    JavaScript总结(二) 系统分析
    .net中将DataTable导出到word、Excel、txt、htm的方法
    World Wind Java开发之十五——载入三维模型
    插入排序:二路插入
    使用HashMap对象传递url參数有用工具类
    mini2440裸机试炼之——DMA直接存取 实现Uart(串口)通信
  • 原文地址:https://www.cnblogs.com/stono/p/8370494.html
Copyright © 2011-2022 走看看