public class ijiajia {
static int j=0;
public static void main(String[] args) throws InterruptedException {
Thread[] threads = new Thread[10];
for(int i=0;i<10;i++){
threads[i] = new Thread(()->{
synchronized (ijiajia.class){
for(int k=0;k<10000;k++){
j++;
}
}
});
}
for(Thread thread:threads) thread.start();
for (Thread thread : threads) thread.join();
System.out.println(j);
}
}
多线程i++
最新推荐文章于 2022-11-07 21:15:02 发布