-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyThreadMain.java
More file actions
29 lines (26 loc) · 884 Bytes
/
MyThreadMain.java
File metadata and controls
29 lines (26 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package concurrent;
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
public class MyThreadMain {
public static void main(String[] args) {
ExecutorService exe=Executors.newCachedThreadPool(new ThreadFactory(){
@Override
public Thread newThread(Runnable r) {
Thread t=new Thread(r);
t.setUncaughtExceptionHandler(new UncaughtExceptionHandler(){
@Override
public void uncaughtException(Thread t, Throwable e) {
System.out.println("UncaughtExceptionHandler Throwable:[" + e
+ "],t.getName():[" + t.getName()+"]");
}
}
);
System.out.println("HandlerThreadFactory en��"+ t.getUncaughtExceptionHandler());
return t;
}
});
exe.execute(new MyThread());
}
}