我是Java并发编码的新手,遇到问题。以下代码在运行时无法停止。谁能告诉我为什么?谢谢
import java.util.concurrent.TimeUnit;
public class Test {
private static boolean stop;
public static void main(String[] args) throws InterruptedException {
new Thread(() -> {
System.out.println(Thread.currentThread());
System.out.println(stop);
while (!stop) {
}
}).start();
TimeUnit.SECONDS.sleep(1);
stop = true;
System.out.println(Thread.currentThread());
System.out.println(stop);
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试运行以下代码,它可能会停止。谁能告诉我为什么?谢谢
import java.util.concurrent.TimeUnit;
public class Test {
private static boolean stop;
public static void main(String[] args) throws InterruptedException {
new Thread(() -> {
System.out.println(Thread.currentThread());
System.out.println(stop);
while (!stop) {
System.out.println(" ");
}
}).start();
TimeUnit.SECONDS.sleep(1);
stop = true;
System.out.println(Thread.currentThread());
System.out.println(stop);
}
}
Run Code Online (Sandbox Code Playgroud) 正如标题,有没有办法信任 Go 中的自签名证书?场景描述:我设置了一个https服务器,它使用自签名证书。当我想用go客户端调用这个服务器时,go需要信任这个自签名证书。