Optimized code
This commit is contained in:
parent
86ef96c29a
commit
453c52987e
@ -24,8 +24,6 @@
|
|||||||
|
|
||||||
package io.github.ehlxr.extension;
|
package io.github.ehlxr.extension;
|
||||||
|
|
||||||
import io.github.ehlxr.did.extension.ExtensionLoader;
|
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,27 +31,37 @@ package io.github.ehlxr.thread;
|
|||||||
public class Main {
|
public class Main {
|
||||||
private static volatile boolean flag = false;
|
private static volatile boolean flag = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1、子线程阻塞主线程将会结束
|
||||||
|
* 2、JVM 会等待待所有子线程结束
|
||||||
|
* <p>
|
||||||
|
* When a Java Virtual Machine starts up, there is usually a single
|
||||||
|
* non-daemon thread (which typically calls the method named main of some
|
||||||
|
* designated class). The Java Virtual Machine continues to execute
|
||||||
|
* threads until either of the following occurs:
|
||||||
|
* <p>
|
||||||
|
* The exit method of class Runtime has been called and the security manager has permitted the exit operation to take place.
|
||||||
|
* All threads that are not daemon threads have died, either by returning from the call to the run method or by throwing an exception
|
||||||
|
* that propagates beyond the run method.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("AlibabaAvoidManuallyCreateThread")
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
System.out.println("wating data...." + Thread.currentThread().getName());
|
System.out.println("wating data...." + Thread.currentThread().getName());
|
||||||
try {
|
while (!flag) {
|
||||||
Thread.sleep(2000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
System.out.println("complete!" + Thread.currentThread().getName());
|
System.out.println("complete!" + Thread.currentThread().getName());
|
||||||
|
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
// Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
|
|
||||||
// new Thread(() -> {
|
new Thread(() -> {
|
||||||
// System.out.println("prepare data..." + Thread.currentThread().getName());
|
System.out.println("prepare data..." + Thread.currentThread().getName());
|
||||||
// flag = true;
|
flag = true;
|
||||||
//
|
|
||||||
// System.out.println("prepare data end..." + Thread.currentThread().getName());
|
System.out.println("prepare data end..." + Thread.currentThread().getName());
|
||||||
// }).start();
|
}).start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user