views:

78

answers:

1

I have ran into a perfomance problem where 880 threads are doing synchronized() { method() } in the same time and this has lead to a major perfomance problem.

Is it possible that there is some limit of threads waiting at synchronized()? Where can I get the limit?

Another question is what is best to put into synchronized( ? ). Because I have different classes accessing that variable, so I can not put synchronized(this).

+2  A: 

There is no way to limit anything with synchronized, for advanced concurrency constructs you need to have a look at http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/package-summary.html.

Regarding what you put inside synchronized(?), which means on what you lock on, it depends on the locking behavior you want to achieve. If you have a global (for example public static Object LOCK = new Object();) which is accessible from all different classes, and you synchronize on that, then all classes will be locking on that one.

Have a look at the java tutorial on synchronization.

cherouvim