Reputation: 228
I have one database and in this we have millions of records. We are reading the record one by one using java and inserting those record to another system on daily basis after end of day. We have been told to make it faster.
I told them we will create multiple thread using thread pool
and these thread will read data parallelly
and inject into another system but I dont know how can we stop our thread to read same data again. how can make it faster and achieve data consistency as well. I mean how can we make this process faster using multithreading
in java
or is there any other way ,other than multithreading to achieve it?
Upvotes: 1
Views: 966
Reputation: 42521
I think you should identify the slowest part in this flow and try to optimize it step by step.
In the described flow you could:
Upvotes: 2
Reputation: 4410
One possible solution for your task would be taking the ids of records in your database, splitting them into chunks (e.g. with size 1000 each) and calling JpaRepository.findAllById(Iterable<ID>)
within Runnable
s passed to ExecutorService.submit()
.
If you don't want to do it manually then you could have a look into Spring Batch. It is designed particularly for bulk transformation of large amounts of data.
Upvotes: 2