synchronized block for an Integer object

后端 未结 3 880
悲哀的现实
悲哀的现实 2020-12-02 01:14

I just came across the synchronized block in Java and wrote a small programm to test how it works.

I create 10 threads and let each thread increment an Integer objec

3条回答
  •  無奈伤痛
    2020-12-02 01:46

    These operations are usually done with Atomic. Have a look here. These structures are specifically designed for multi-threaded computation. Normal implementations are not thread safe.

提交回复
热议问题