What does 'synchronized' mean?

后端 未结 17 1606
广开言路
广开言路 2020-11-22 00:13

I have some questions regarding the usage and significance of the synchronized keyword.

  • What is the significance of the synchronized
17条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 00:28

    The synchronized keyword prevents concurrent access to a block of code or object by multiple threads. All the methods of Hashtable are synchronized, so only one thread can execute any of them at a time.

    When using non-synchronized constructs like HashMap, you must build thread-safety features in your code to prevent consistency errors.

提交回复
热议问题