小编Wei*_*ong的帖子

线程无法正常停止

我是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)

java

2
推荐指数
1
解决办法
99
查看次数

如何信任自签名证书

正如标题,有没有办法信任 Go 中的自签名证书?场景描述:我设置了一个https服务器,它使用自签名证书。当我想用go客户端调用这个服务器时,go需要信任这个自签名证书。

ssl-certificate go

2
推荐指数
1
解决办法
5617
查看次数

标签 统计

go ×1

java ×1

ssl-certificate ×1