亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

java - int 是線程安全的嗎?
ringa_lee
ringa_lee 2017-04-18 10:54:59
0
3
911

例如在springmvc的controller中

    public class EnchashmentController extends BaseController {
            private int a = 0;
            
            @requestMapping("")
            public ModelAndView add(){
                a++;
                return null;
            }
    }

每一個(gè)請(qǐng)求都在這里都執(zhí)行一次a加一操作,1萬(wàn)次請(qǐng)求(并發(fā))甚至更多次以后,這里輸出的a是否就是 10000 或者 100000呢?

ringa_lee
ringa_lee

ringa_lee

reply all(3)
阿神

It should be said that a++ is not thread-safe

小葫蘆

AtomicInteger should be the answer you want

阿神

Not safe. . . .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template