Should you synchronize the run method? Why or why not?

前端 未结 7 1305
温柔的废话
温柔的废话 2020-11-29 07:34

I have always thought that synchronizing the run method in a java class which implements Runnable is redundant. I am trying to figure out why people do this:

7条回答
  •  暖寄归人
    2020-11-29 07:57

    From my experience, it's not useful to add "synchronized" keyword to run() method. If we need synchronize multiple threads, or we need a thread-safe queue, we can use more appropriate components, such as ConcurrentLinkedQueue.

提交回复
热议问题