I have following requirement –
I have to
1.query a table and select approx 20k rows matching somecondition.
2.process those records and change some fields.
3.update the same table with changed records.
How I can use multithreading to batch SELECT,PROCESS and UPDATE records?
Any best practices?
What is optimum thread number to use?
Any alternative approaches?
! ROWS TO BE USED ARE INDEPENDENT OF EACH OTHER
You realize, of course, that unless the rows you’re processing are COMPLETELY independent of each other, processing in concurrent threads will probably HURT performance.
Right?
Anyway, my best advice:
1) Don’t use use multiple threads unless you absolutely need to
2) Even then, don’t use multiple threads unless the “batches” are independent (nothing in one batch will ever need to wait on a lock held by another)
3) Do the query, processing and update together, as a single batch
… and, most important …
4) Use stored procedures wherever, whenever possible:
http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/ad/c0007033.htm