0 点赞 评论 收藏
分享
09-02 12:40
门头沟学院 后端 0 点赞 评论 收藏
分享
0 点赞 评论 收藏
分享
08-06 20:41
门头沟学院 后端 来一个offer咩:import java.util.concurrent.atomic.AtomicInteger;
public class AlternatePrintingNumbersAtomic {
private static AtomicInteger count = new AtomicInteger(1);
private static final int MAX_COUNT = 10;
public static void main(String[] args) {
Thread thread1 = new Thread(() -> {
while (count.get() <= MAX_COUNT) {
if (count.get() % 2 == 1) {
System.out.println(Thread.currentThread().getName() + ": " + count.getAndIncrement());
}
}
}, "Thread1");
Thread thread2 = new Thread(() -> {
while (count.get() <= MAX_COUNT) {
if (count.get() % 2 == 0) {
System.out.println(Thread.currentThread().getName() + ": " + count.getAndIncrement());
}
}
}, "Thread2");
thread1.start();
thread2.start();
}
}
查看3道真题和解析
0 点赞 评论 收藏
分享
关注他的用户也关注了: