我有一个由 pm2 管理的节点服务器。
每当代码更改时我都会运行命令
pm2 重新加载 config.json --env staging
但直到我运行命令后更改才会反映出来
pm2 杀死
手动在服务器上。
我的情况下 PM2 手表已关闭。
我正在学习易变量.我知道volatile的作用,我为Volatile变量编写了一个示例程序,但没有按预期工作.
为什么"计数"的最终值有时会低于2000.我使用了volatile,因此系统不应该缓存"count"变量,值应该始终为2000.
当我使用synchronized方法时它工作正常但不是volatile关键字.
public class Worker {
private volatile int count = 0;
private int limit = 10000;
public static void main(String[] args) {
Worker worker = new Worker();
worker.doWork();
}
public void doWork() {
Thread thread1 = new Thread(new Runnable() {
public void run() {
for (int i = 0; i < limit; i++) {
count++;
}
}
});
thread1.start();
Thread thread2 = new Thread(new Runnable() {
public void run() {
for (int i = 0; i < limit; …Run Code Online (Sandbox Code Playgroud)