johnson666's recent timeline updates
johnson666

johnson666

V2EX member #291227, joined on 2018-02-10 13:46:49 +08:00
johnson666's recent replies
Jan 25, 2021
Replied to a topic by Cbdy Java 求一个 Java 面试题的最佳实践
原子变量

public class Test {
public static void main(String[] args) {
AtomicInteger at = new AtomicInteger();
for (int i = 0; i < 3; i++) {
MyThread t = new MyThread(at, i);
t.start();
}
}
}

class MyThread extends Thread {
private AtomicInteger at;
private int index;

public MyThread(AtomicInteger at, int index) {
this.at = at;
this.index = index;
}

@Override
public void run() {
while(true) {
if(at.get() % 3 == index) {
System.out.print((char)('a' + index));
at.incrementAndGet();
}
}
}
}
真不懂为啥这么用
Feb 15, 2018
Replied to a topic by isCyan 支付宝 大家集五福拿了多少钱?
1.98
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   908 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 12ms · UTC 19:54 · PVG 03:54 · LAX 12:54 · JFK 15:54
♥ Do have faith in what you're doing.