3 messages in com.mysql.lists.javaRe: Why does mm.mysql have "synchroni...| From | Sent On | Attachments |
|---|---|---|
| Shankar Unni | 20 Mar 2002 13:09 | |
| Mark Matthews | 20 Mar 2002 17:19 | |
| Shankar Unni | 20 Mar 2002 18:25 |
| Subject: | Re: Why does mm.mysql have "synchronized" on every ResultSet method?![]() |
|---|---|
| From: | Mark Matthews (mmat...@thematthews.org) |
| Date: | 03/20/2002 05:19:41 PM |
| List: | com.mysql.lists.java |
----- Original Message ----- From: "Shankar Unni" <shan...@intruvert.com> To: <ja...@lists.mysql.com> Sent: Wednesday, March 20, 2002 3:09 PM Subject: Why does mm.mysql have "synchronized" on every ResultSet method?
[obfilter: mysql database query]
I don't see a "synchronized" spec on java.sql.ResultSet itself - is is expected that ResultSets are self-synchronizing? But every getXXX() method of mm.mysql's ResultSet has a synchronized specification.
1. Interfaces can't specify synchronized or not. 2. You have to dig _way_ down deep in the JDBC spec to see that they say that JDBC drivers should be thread safe. Which means that because of the way updatable result sets work, and the fact that result sets do hold instance data, they need to be fully-synchronized to meet the spec.
This slows down the ResultSet retrieval tremendously, especially since it is *extremely* unlikely that you have multiple threads trying to access the same ResultSet (what would that mean, anyway, if one thread did a next() while the other was fetching columns from the previous row?)
It is not "extremely" unlikely, I used to think that way, too. I then had enough requests from fat-client GUI builders that they were having problems with Swing apps and MM.MySQL due to no syncrhonization (look at a couple of versions ago, no synchronization at all except a connection-wide mutex). Besides In a modern JVM, synchronization primitives are not that slow.
Can we just toss the "synchronized" from these methods?
No. However, for MM.MySQL-3.0, I'm thinking of providing synchronization "wrappers", sort of how java collections work, so that people that are doing servlet/EJB development don't need to pay a synchronization penalty, but people that really need it can have it. It should be relatively easy to pull off with JDK-1.3+'s proxy stuff.
-Mark




