java - Any reason NOT to slap the 'synchronized' keyword everywhere? -


in java project, every non-static method i've written synchronized. i've decided fix code today, removing of synchronized keywords. right there created several threading issues took quite while fix, no increase in performance. in end reverted everything.

i don't see else writing code "synchronized" everywhere. there reason shouldn't have "synchronized" everywhere?

what if don't care performance (ie. method isn't called more once every few seconds)?

of course - performance. monitors have cost.

the answer neither removing nor adding synchronization in random fashion. better read brian goetz' "java concurrency in practice" or doug lea's "java threads" books understand how properly. , learn new concurrent packages well, of course.

multithreading lot more synchronized keyword.


Comments