So far, we have been splitting work into multiple, independent jobs, and then we used a pool of threads to parallelize I/O operations without great effort. However, a database server is already very well prepared for parallelized access, as it is designed for serving a number of concurrent users. How can we optimize our client applications to take advantage of both multithreading and parallelized database access?
The answer is simple; it depends on the kind of application we need:
If we need to optimize something that runs like a time-consuming batch process, we will use specialized subclasses of our well-known
ParallelAlgorithmPiece
andParallelAlgorithm
classes to develop a new algorithm for parallelizing database access and collecting results.If we need to dispatch many concurrent independent jobs, we will use a pool of threads provided by the
ThreadPool
class, combined with an independent class, to run the code for each thread.