Optimized code

dev
ehlxr 2021-02-13 18:03:11 +08:00
parent 86ef96c29a
commit 453c52987e
2 changed files with 22 additions and 14 deletions

View File

@ -24,8 +24,6 @@
package io.github.ehlxr.extension;
import io.github.ehlxr.did.extension.ExtensionLoader;
import java.lang.annotation.*;
/**

View File

@ -31,27 +31,37 @@ package io.github.ehlxr.thread;
public class Main {
private static volatile boolean flag = false;
/**
* 1线线
* 2JVM 线
* <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 {
new Thread(() -> {
System.out.println("wating data...." + Thread.currentThread().getName());
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
while (!flag) {
}
System.out.println("complete!" + Thread.currentThread().getName());
}).start();
// Thread.sleep(2000);
Thread.sleep(2000);
// new Thread(() -> {
// System.out.println("prepare data..." + Thread.currentThread().getName());
// flag = true;
//
// System.out.println("prepare data end..." + Thread.currentThread().getName());
// }).start();
new Thread(() -> {
System.out.println("prepare data..." + Thread.currentThread().getName());
flag = true;
System.out.println("prepare data end..." + Thread.currentThread().getName());
}).start();
}
}