ThreadGroup group =newThreadGroup("groupA");Thread t =newThread(group,"A");
t.setUncaughtExceptionHandler(newThread.UncaughtExceptionHandler(){@OverridepublicvoiduncaughtException(Thread t,Throwable e){System.out.println("线程"+ t.getName()+"出现了异常。");}});
一、线程的几种状态NEW:新创建的线程,还未运行RUNABLE:正在运行BLOCKED:受阻塞并等待某个监视器锁WAITING:无限的等待,知道其他线程执行了某个操作(wait()方法)TIME_WAITING:等待指定时间后执行线程TERMINATED:线程已经退出,结束运行二、线程组可以把线程归属到某一个线程组中。ThreadGroup group = new ThreadGroup(“groupA”); Thread t = new Thread(group,“A”);线程组