Avatar
0
Vu Luong Anh Pundit
Warning khi dùng synchronized
Em thấy có warnings ở chỗ synchronized (gameService)synchronized (room). Anh giải thích giúp em vì sao có warnings này được không ạ? <img class="alignnone size-large wp-image-438" src="https://stackask.com/wp-content/uploads/2021/08/Screen-Shot-2021-08-02-at-00.23.15-1024x640.png" alt="" /> <img class="alignnone size-large wp-image-439" src="https://stackask.com/wp-content/uploads/2021/08/Screen-Shot-2021-08-02-at-00.23.43-1024x640.png" alt="" />
  • Answer
game-box freetank
Remain: 5
2 Answers
Avatar
tvd12 Enlightened
tvd12 Enlightened
Warning này là do cái gameService và room có thể null em ạ, tuy nhiên thực tế thì không bao giờ em ạ
  • 0
  • Reply
Avatar
Em đọc thấy bảo không nên dùng synchronized với non-final field. Mà cái gameService của mình là non-final, anh giải thích chỗ này được không ạ? https://stackoverflow.com/questions/6910807/synchronization-of-non-final-field/21462631
  • 0
  • Reply