标签:sys ali 服务端 on() type 控制 llb ram exit
void run()
void run()
public class Thread extends Object implements Runnable
public class Thread extends Object implements Runnable
Thread.dumpStack();
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:1329)
at Test.main(Test.java:6)
new Throwable().printStackTrace();
java.lang.Throwable
at Test.main(Test.java:6)
Thread.dumpStack();
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:1329)
at Test.main(Test.java:6)
new Throwable().printStackTrace();
java.lang.Throwable
at Test.main(Test.java:6)
Map<Thread, StackTraceElement[]> map = Thread.getAllStackTraces();
for (Thread thread : map.keySet()) {
System.out.println(thread.toString() + " " + Arrays.toString(map.get(thread)));
}
Thread[Finalizer,8,system] [java.lang.Object.wait(Native Method), java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143), java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164), java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)]
Thread[Attach Listener,5,system] []
Thread[Signal Dispatcher,9,system] []
Thread[Reference Handler,10,system] [java.lang.Object.wait(Native Method), java.lang.Object.wait(Object.java:502), java.lang.ref.Reference.tryHandlePending(Reference.java:191), java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)]
Thread[main,5,main] [java.lang.Thread.dumpThreads(Native Method), java.lang.Thread.getAllStackTraces(Thread.java:1603), Test.main(Test.java:8)]
Map<Thread, StackTraceElement[]> map = Thread.getAllStackTraces();
for (Thread thread : map.keySet()) {
System.out.println(thread.toString() + " " + Arrays.toString(map.get(thread)));
}
Thread[Finalizer,8,system] [java.lang.Object.wait(Native Method), java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143), java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164), java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)]
Thread[Attach Listener,5,system] []
Thread[Signal Dispatcher,9,system] []
Thread[Reference Handler,10,system] [java.lang.Object.wait(Native Method), java.lang.Object.wait(Object.java:502), java.lang.ref.Reference.tryHandlePending(Reference.java:191), java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)]
Thread[main,5,main] [java.lang.Thread.dumpThreads(Native Method), java.lang.Thread.getAllStackTraces(Thread.java:1603), Test.main(Test.java:8)]
System.out.println(Arrays.toString(Thread.currentThread().getStackTrace()));
[java.lang.Thread.getStackTrace(Thread.java:1552), Test.main(Test.java:7)]
System.out.println(Arrays.toString(Thread.currentThread().getStackTrace()));
[java.lang.Thread.getStackTrace(Thread.java:1552), Test.main(Test.java:7)]
枚举 Thread.State
Thread.State.NEW 至今尚未启动的线程处于这种状态。
Thread.State.RUNNABLE 正在 Java 虚拟机中执行的线程处于这种状态。
Thread.State.BLOCKED 受阻塞并等待某个监视器锁的线程处于这种状态。
Thread.State.WAITING 无限期地等待另一个线程来执行某一特定操作的线程处于这种状态。
Thread.State.TIMED_WAITING 等待另一个线程来执行取决于指定等待时间的操作的线程处于这种状态。
Thread.State.TERMINATED 已退出的线程处于这种状态。
在给定时间点上,一个线程只能处于一种状态。这些状态是虚拟机状态,它们并没有反映所有操作系统线程状态。
枚举 Thread.State
Thread.State.NEW 至今尚未启动的线程处于这种状态。
Thread.State.RUNNABLE 正在 Java 虚拟机中执行的线程处于这种状态。
Thread.State.BLOCKED 受阻塞并等待某个监视器锁的线程处于这种状态。
Thread.State.WAITING 无限期地等待另一个线程来执行某一特定操作的线程处于这种状态。
Thread.State.TIMED_WAITING 等待另一个线程来执行取决于指定等待时间的操作的线程处于这种状态。
Thread.State.TERMINATED 已退出的线程处于这种状态。
在给定时间点上,一个线程只能处于一种状态。这些状态是虚拟机状态,它们并没有反映所有操作系统线程状态。
Thread[Thread-0,5,main]
Thread[main,5,main]
Thread[Thread-0,5,main]
Thread[main,5,main]
System.out.println(new Thread().getThreadGroup());
java.lang.ThreadGroup[name=main,maxpri=10]
System.out.println(new Thread().getThreadGroup());
java.lang.ThreadGroup[name=main,maxpri=10]
public class Test {
public static void main(String[] args) {
new Parent().start();
}
// 父线程
static class Parent extends Thread {
public void run() {
System.out.println("Parent start");
Child child = new Child();
child.start();
try {
child.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Parent end");
}
}
// 子线程
static class Child extends Thread {
public void run() {
System.out.println("Child start");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Child end");
}
}
}
public class Test {
public static void main(String[] args) {
new Parent().start();
}
// 父线程
static class Parent extends Thread {
public void run() {
System.out.println("Parent start");
Child child = new Child();
child.start();
try {
child.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Parent end");
}
}
// 子线程
static class Child extends Thread {
public void run() {
System.out.println("Child start");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Child end");
}
}
}
Parent start
Child start
Child end
Parent end
Parent start
Child start
Child end
Parent end
Parent start
Parent end
Child start
Child end
Parent start
Parent end
Child start
Child end
Thread daemonTread = new Thread();
daemonThread.setDaemon(true); // 设定 daemonThread 为 守护线程
daemonThread.isDaemon(); // 验证当前线程是否为守护线程,返回 true 则为守护线程
Thread daemonTread = new Thread();
daemonThread.setDaemon(true); // 设定 daemonThread 为 守护线程
daemonThread.isDaemon(); // 验证当前线程是否为守护线程,返回 true 则为守护线程
Thread thread = new Thread(() -> System.out.println(new Thread().isDaemon()));//true
thread.setDaemon(true);
thread.start();
Thread thread = new Thread(() -> System.out.println(new Thread().isDaemon()));//true
thread.setDaemon(true);
thread.start();
public class Test {
public static void main(String[] args) {
Thread thread = new Thread(() -> {
try {
System.out.println("start");
Thread.sleep(1000);//阻塞1秒后运行
FileWriter writer = new FileWriter(new File("d://daemon.txt"), true);
writer.write("daemon");
writer.close();
System.out.println("end");
} catch (Exception e) {
e.printStackTrace();
}
});
thread.setDaemon(true); //设置守护线程时不会有任何内容写入文件
thread.start(); //开始执行分进程
}
}
public class Test {
public static void main(String[] args) {
Thread thread = new Thread(() -> {
try {
System.out.println("start");
Thread.sleep(1000);//阻塞1秒后运行
FileWriter writer = new FileWriter(new File("d://daemon.txt"), true);
writer.write("daemon");
writer.close();
System.out.println("end");
} catch (Exception e) {
e.printStackTrace();
}
});
thread.setDaemon(true); //设置守护线程时不会有任何内容写入文件
thread.start(); //开始执行分进程
}
}
标签:sys ali 服务端 on() type 控制 llb ram exit
原文地址:https://www.cnblogs.com/baiqiantao/p/9168827.html