c语言sscanf函数的用法是什么
274
2022-11-19
Thread多线程进行加锁控制执行顺序synchronized保证执行原子性
package com.tl.executor.locks; public class Sync01 implements Runnable{ static int i=0; @Override public void run() { for (int j=0;j<10;j++){ synchronized (Sync01.class) { i++; System.out.println(Thread.currentThread().getName()+"||||||||"+i); } } } public static void main(String[] args) throws InterruptedException { Sync01 sync01=new Sync01(); Sync01 sync02=new Sync01(); Thread thread1=new Thread(sync01); Thread thread2=new Thread(sync02); thread1.start(); thread2.start(); //thread1.join(); //thread2.join(); Thread.sleep(1000); System.out.println(i); }}/**** * 运行结果:Thread-0||||||||1Thread-1||||||||2Thread-1||||||||3Thread-1||||||||4Thread-1||||||||5Thread-1||||||||6Thread-1||||||||7Thread-1||||||||8Thread-1||||||||9Thread-1||||||||10Thread-1||||||||11Thread-0||||||||12Thread-0||||||||13Thread-0||||||||14Thread-0||||||||15Thread-0||||||||16Thread-0||||||||17Thread-0||||||||18Thread-0||||||||19Thread-0||||||||2020 * * */
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~