3 ms·
Monitors are especially strange when I learned Java. I mean, why would you put a synchronization feature into every object? It's not necessary in the vast major
by kccqzy 4y ago
Monitors are especially strange when I learned Java. I mean, why would you put a synchronization feature into every object? It's not necessary in the vast majority of the time.
Maybe the programming style at the time had something to do with it. Maybe they thought every class needs to be thread safe and mutable.
- layer8 4y agoThis was over 30 years ago when there was still a lack of awareness that locks don't compose [0]. Look at the early JRE classes like Vector, Hashtable, and StringBuffer, whose operations are synchronized. The idea was that since you'd potentially want to synchronize access to any mutable object (because you'd want to be able to share any object between threads), and most objects are mutable, that the most convenient solution would be for every object to have that functionality built in. [0] https://en.wikipedia.org/wiki/Lock_(computer_science)#Lack_of_composability https://en.wikipedia.org/wiki/Lock_(computer_science)#Lack_o...