wood burning stoves 2.0*
The moose likes JDBC and the fly likes multiple inserts with multiple connections into same db table. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "multiple inserts with multiple connections into same db table." Watch "multiple inserts with multiple connections into same db table." New topic
Author

multiple inserts with multiple connections into same db table.

Scott William Sinclair
Greenhorn

Joined: Oct 12, 2004
Posts: 8
Hi Guys,

I hope someone can help
I have two or more threads which are inserting into the same target database table, each having their own connection. The connection has autoCommit set to false and I am performing batch inserts (batch size 10) and am only commiting once all inserts have been performed per thread.

My problem is that I am getting a deadlock, which I can't understand because I am only inserting into the one table.

I am using sybase 12.5.1

some output from sp_lock is below


Any help would be appreciated,

thanks.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

are all thread invoking same method for insert.

if yes then you can add synchonized keyword to you method.
[ October 28, 2004: Message edited by: Shailesh Chandra ]

Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Scott William Sinclair
Greenhorn

Joined: Oct 12, 2004
Posts: 8
Hi,

Thanks for the response, there is no common method for inserting.

I managed to change the server locking schema to "datarows" instead of "allpages", so it is row based instead of table based and that seems to have fixed it. I'm just confused how a deadlock could ocurr in the first place, since normally a deadlock requires two resources to be in contention.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: multiple inserts with multiple connections into same db table.
 
Similar Threads
Problem facing with executebatch function
Simultanious Inserting Data
Paging-Query based
Resultset with million rows
Retrieve huge result set from DB in chunks