Re: fwd: BUG ? dead lock in connector/J 3.0.8

Re: fwd: BUG ? dead lock in connector/J 3.0.8

am 05.08.2003 18:08:37 von Mark Matthews

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Sinisa Milivojevic wrote:

> Please reply to user and bugs@..
>
>
>
> ------------------------------------------------------------ ------------
>
> Subject:
> BUG ? dead lock in connector/J 3.0.8
> From:
> Andreas Mühlbradt
> Date:
> Mon, 28 Jul 2003 17:21:35 +0200
> To:
>
>
>
> Hello,
>
> the following code fragment seems to cause a dead lock in Connector/J
3.0.8.
>
> static Connection con = null;
>
> public static void main (String args[]) throws Exception
> {
> Driver driver = (Driver)
Class.forName("com.mysql.jdbc.Driver").newInstance();
> con = driver.connect("jdbc:mysql://.../...", null);
>
> new Thread() {
> public void run() {
> try {
> Statement stat = con.createStatement();
> while(true) {
> stat.executeQuery("select 1").close();
> System.out.println("select 1");
> }
> } catch (Exception e) {}
> }
> }.start();
>
> while(true) {
> Statement stat = con.createStatement();
> stat.setMaxRows(1);
> System.out.println("setMaxRows");
> stat.close();
> }
> }
>
>
> The code is very useless, I know. But it shows the problem. The
problem occurs within a complex application and I reduced it
> on these couple of lines.
>
> The point is that two threads use simultaneously use same connection
with different statements. A thread creates one statement and sends
selects only, closing implicit resultset. Main loop seems to cause the
deadlock by creating permanently new statements, call method setMaxRow
and close statement again.
> I would expect to get many of output on stdout because of two threads
running... But after 5 or 10 lines of output nothing happens...
> Blocking occurs very fast (within a second). After deadlock every
select or insert send on the same connection will block.
>
> If I use LIMIT clause in query everything is fine, but I want to use
method setMaxRows to be independent from used database ;-)
> New statement on each query I need to wrap statement and resultset by
my own classes...
>
> I've tried connector/J 3.0.6 and 3.0.8, java 1.3.1, java 1.4.1.
Windoze or Linux, it doesn't matter...
> Dead lock occured on multi processor system, but on single it's the same.
>
> I think and hope this isn't a theoretical problem only. At the moment
I've worked around it in my wrapper classes. But it was very hard to
find and I think it would be nice to have a solution in next releases ?
>
> Please tell me, if it is really a bug, if it is known or if I am to
stupid ?!?
>
> Thanks,
>
> Andreas Mühlbradt

It might be a bug, but no one has reported it until now. On the
otherhand, are you sure you really _want_ to share a connection between
two threads? It doesn't buy you anything, it isn't the way JDBC is
designed to be used, and it will actually lead to slower performance in
most cases. See my article about this topic at
http://www.mysql.com/newsletter/2003-04/a0000000154.html

I'll see if I can track this down, but it might be timing dependent. If
you can get me a stack dump (see your JVM documentation, it usually
involves sending a certain signal via 'kill') that shows what is waiting
on what, that will help a lot.

-Mark


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQE/L9aEtvXNTca6JD8RAlB/AKC2OFTPhGxm4CeJMrUGoYjdUtLB7wCe PTd9
LKrTRTMf2+lZKIpouuQC3yY=
=P31d
-----END PGP SIGNATURE-----


--
MySQL Bugs Mailing List
For list archives: http://lists.mysql.com/bugs
To unsubscribe: http://lists.mysql.com/bugs?unsub=gcdmb-bugs@m.gmane.org