• Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronization

 
Jay Damon
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This post is somewhat related to my previous post regarding performance issues.

There is speculation that the poor performance times we are observing on the web server performance tests is do to "excessive" synchronization on a policy class I coded. There are 4 methods on the policy class that are synchronized because they load data "en masse". The signature for each of the 4 is similar to the following:

synchronized boolean getAllLines()

The methods are all package access and can only be invoked by a one method in a related policy object. These methods are designed to retrieve a group of table rows using 1 SQL call (thus mininmizing both DB and network time) the first time the data is required. Subsequent invocations, if any, "fall through" the method because the data has already been retrieved.

Theoretically, in our environment, these methods would not have to be synchronized because we do not currently access policy instances on multiple threads. However, this was a little defensive programming on my part to ensure potential multiple retrievals would never become an issue.

The worry (among other developers) is that these methods are "locking" ALL policy objects when any one policy object is in one of these methods. My understanding is that only the policy INSTANCE for that method is "locked".
To lock all policy objects, my understanding is that I would have to code something similar to the following:

static synchronized boolean getAllLines()

OR

synchronized(Policy.class) (within a method)

Is my understanding correct or is this a potential problem?

I realize that my synchronization of these 4 methods does have some performance impact. Normally however, each method is invoked only once and, perhaps, not at all depending upon the scenario in which the policy object is being created, i.e. the data may not be required.

Further, I realize the merits on synchronizing these methods can be debated. However, I hardly believe such synchronization is responsible for the 30+ second response times note in my previous post. Opinions, please.
[ November 18, 2005: Message edited by: Jay Damon ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your understanding is correct - a synchronized instance method uses the instance as monitor. Different instances can run the method in parallel.

Your problem is elsewhere.
 
Paul Clapham
Sheriff
Posts: 21872
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless the object you are synchronizing on is the servlet containing that code, in which case simultaneous requests to that servlet could lock one another out even though they are looking at different policies.

However it looks like you're synchronizing on a policy object, in which case you should be okay.
[ November 18, 2005: Message edited by: Paul Clapham ]
 
Jay Damon
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ilya,

Thank you for confirming my understanding of synchronization.

Paul,

You are correct. I am synchronizing on a policy object. No other synchronization is being performed (as far as I know).

Jay
[ November 18, 2005: Message edited by: Jay Damon ]
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jay, if you take a core dump at a time when slow response is observed, you can easily see what thread is waiting for what resource. This may aid you in proving your point.

You can take a core dump without killing jvm.
 
kundan sinha
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How can i take a jvm dump when server is running. i am using sun one server and sometimes it shows a slow response.

any suggestions

with regards
Kundan
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by kundan sinha:
Hi,

How can i take a jvm dump when server is running. i am using sun one server and sometimes it shows a slow response.

any suggestions

with regards
Kundan


You should start a new topic on this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!