Buffering db inserts in multithreaded program

Posted by Winter on Stack Overflow See other posts from Stack Overflow or by Winter
Published on 2010-05-11T15:26:03Z Indexed on 2010/05/11 15:34 UTC
Read the original article Hit count: 189

I have a system which breaks a large taks into small tasks using about 30 threads as a time. As each individual thread finishes it persists its calculated results to the database. What I want to achieve is to have each thread pass its results to a new persisance class that will perform a type of double buffering and data persistance while running in its own thread.

For example, after 100 threads have moved their data to the buffer the persistance class then the persistance class swaps the buffers and persists all 100 entries to the database. This would allow utilization of prepared statements and thus cut way down on the I/O between the program and the database.

Is there a pattern or good example of this type of multithreading double buffering?

© Stack Overflow or respective owner

Related posts about java

Related posts about multithreading