java - Multithreading for List of Objects -
i have list of 800 customer objects , each customer object in loop needs fetch additional data database, single thread operation taking lot of time.
my approach split initial list in multiple lists of 4 , execute each list in parallel each other. can 1 come demo code skeleton problem statement.
i confused whether should write db queries , business logic inside run() method of class implementing runnable interface or better approach there?
800 not large number of rows bring back. what's killing loop, you're performing separate query each of these rows. called n + 1 selects antipattern.
using multiple threads not improve anything, network round trips problem before , adding threads doesn't make better. instead write 1 query join customer whatever needs, bringing data in 1 resultset. minimizes number of trips across network data.
Comments
Post a Comment