Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > is a MySQL write lock automatically released when a pooled connectionis closed?

Reply
Thread Tools

is a MySQL write lock automatically released when a pooled connectionis closed?

 
 
christopher@dailycrossword.com
Guest
Posts: n/a
 
      03-07-2008
Greetings,
I am using JDBC (probably version 2), and I use code like this to open
and close connections:

Connection con=null;
Statement sqlstatement=null;
ResultSet sqlresults=null;
PreparedStatement pStatement=null;
try {
con=DriverManager.getConnection("name of connection pool");
....
} catch (SQLException e) {/*handle error*/);
} finally {
if(con!=null) try { con.close();} catch (SQLException e){}
if(sqlstatement!=null) try { sqlstatement.close();} catch
(SQLException e){}
if(pStatement!=null) try { pStatement.close();} catch
(SQLException e){}
if(sqlresults!=null) try { sqlresults.close();} catch
(SQLException e){}
}

Which I think is like belt and suspenders. In a new connection I will
be locking the table, and I need to be certain it is unlocked when I
am done. I am planning to add the "unlock tables" update to the first
line of the finally block, before the close(). I am wondering what
will happen if there is a hiccup (broken pipe in the connection pooler
or something) -- does the lock ever get released?

} catch (SQLException e) {/*handle error*/);
} finally {
if(con!=null) try {
sqlstatement.execute("UNLOCK TABLES;"); // (or whatever
con.close();
} catch (SQLException e){}
if(sqlstatement!=null) try { sqlstatement.close();} catch
(SQLException e){}
if(pStatement!=null) try { pStatement.close();} catch
(SQLException e){}
if(sqlresults!=null) try { sqlresults.close();} catch
(SQLException e){}
}


This really exposes a fundamental lack of understanding on my part
about the nature of connection pooling -- do temporary tables exist
for the life of pooled connections or just for the current use of the
connector? Variables? When are pooled connections ever actually
closed?

Thanx all!
 
Reply With Quote
 
 
 
 
christopher@dailycrossword.com
Guest
Posts: n/a
 
      03-09-2008
On Mar 7, 2:29 pm, christop...@dailycrossword.com wrote:
> Greetings,
> I am using JDBC (probably version 2), and I use code like this to open
> and close connections:


snip

I have examined the source for the pooled connection's close() method,
and it simply returns the connection object to a generic pool (Jakarta
commons DBCP and Pool), so it seems as though no reset is ever done to
release locks or close temporary tables, etc., as is is in other
pooled connectors. I have read a number of posts from several years
ago either asking the same question, or declaring that 'table locks'
should never be used in 'robust applications'. I am very concerned
that an uncaught exception or transient network failure would lock the
table indefinitely.

For what it's worth I am re-designing that portion of the application
to produce meaningful (if a little stale) data without using the table
locks.

Cheers!
 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      03-10-2008
wrote:
> On Mar 7, 2:29 pm, christop...@dailycrossword.com wrote:
>> Greetings,
>> I am using JDBC (probably version 2), and I use code like this to open
>> and close connections:


> I have examined the source for the pooled connection's close() method,
> and it simply returns the connection object to a generic pool (Jakarta
> commons DBCP and Pool), so it seems as though no reset is ever done to
> release locks or close temporary tables, etc., as is is in other
> pooled connectors. I have read a number of posts from several years
> ago either asking the same question, or declaring that 'table locks'
> should never be used in 'robust applications'. I am very concerned
> that an uncaught exception or transient network failure would lock the
> table indefinitely.
>
> For what it's worth I am re-designing that portion of the application
> to produce meaningful (if a little stale) data without using the table
> locks.


LOCK TABLE is a hack. A hack that does not fit well with Java.

InnoDB tables, transactions and a suitable transaction isolation
level.

Arne
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Read-Write Lock vs primitive Lock() k3xji Python 7 12-30-2008 10:19 PM
# of pooled connections seem too high Bob ASP .Net 2 02-01-2005 07:40 PM
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. Guoqi Zheng ASP .Net 4 06-03-2004 06:39 PM
all pooled connections were in use dotNET Developer ASP .Net 2 02-24-2004 08:01 PM
Old (pooled) ASP pages makes dllhost.exe to hang after inst. .Net 1.1 Dag Sunde ASP .Net 0 12-03-2003 02:52 PM



Advertisments