JAVA的synchronized关键字与concurrent并发包的性能比较。

释放双眼,带上耳机,听听看~!

     private static AtomicInteger mySessionID= new AtomicInteger(-2);

    public static int getMySessionID() {

        return mySessionID.decrementAndGet();

    }

    private static int mySessionID= -2;

    public static synchronized int getMySessionID() {

        return mySessionID–;

    }

经过开了300个线程,每个线程做一万次以上循环,发现,竟然Atomic的原子类竟然平均高出synchronized差不多3倍以上,并且速度非常稳定,而synchronized表现不稳定,而且速度也慢。

给TA打赏
共{{data.count}}人
人已打赏
安全技术

随笔-vue项目引入jQuery

2021-12-21 16:36:11

安全技术

从零搭建自己的SpringBoot后台框架(二十三)

2022-1-12 12:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索