简体   繁体   中英

Java concurrency in DB write operation

I have got one scenario where I need to insert 16k records in a DB table. So along with normal DB batch insert I have created Callable task which will take up respective batch(size of 500 records) and will do insertion in independent manner. I am curious to know how underlying database will take these requests. Does database locking at page level will block rest of java threads until first thread with batch of 500 records get committed?

From Sybase IQ's documentation :

Sybase allows multiple readers, but only one writer to a table.

So, unless you open and close the transaction for every row you insert (which will be slow), your Threads will have to wait until one transaction closes to start a new one.

My answer is for Sybase ASE. For Sybase IQ see Guillaume's answer.

Does database locking at page level will block rest of java threads until first thread with batch of 500 records get committed?

That depends on what locking granularity you have set. According to Sybase's doc , there are three locking granularities:

  • Allpages locking, which locks datapages and index pages
  • Datapages locking, which locks only the data pages
  • Datarows locking, which locks only the data rows

So, if you select Allpages your threads will block until the current batch gets committed. Otherwise, your threads will not block, but will naturally incur a higher locking overhead.

For full details on Sybase ASE's locking granularity, see this documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM