Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Java: Why not synchronize everything?

Started by Tree Penguin Sep 22, 2006 at 9:16 AM 2 replies 1.3k views
Original Post
Tree Penguin
Tree Penguin
Hi, i have a bunch of Java objects that are accesible to many players at a time (possibly hundreds per object). Many of these objects are writable so i decided to use synchronize on them to ensure thread safety. As the code isn't very dependent on speed, could it hurt to just make everything synchronized? As everything has to be executed anyway what difference does it make if i do them at the same time or just one at a time. I know there are some performance penalties associated with synchronized, but what performance penalties can i expect (especially for small functions like reading a string from an sql resultset), will it decrease by 2 percent or more like 50? Thanks!
Son of Cain
Son of Cain
Err.. I don't really get what you mean by "make everything synchronized". The more you "localize" the synchronized code, the better - do not broaden its scope unnecessarily. Not only because of performance reasons - although it would take lots of access to make any penalty noticeable - but also as a good programming practice.

Stick to it man, it makes more sense to "synchronize" only what you need to ;)
a.k.a javabeats at yahoo.ca

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.