My project requires a service that will repeatable migration between two tables on two different databases. I have implemented this via Hibernate. So, I have a service that fetches data from the primary database table and then migrate it to the second database table, however, my primary database table has over 200000 rows and the iterator takes quite a long time to complete the task.
What should I use to speed up the process?
Here is the Service code:
@Service
public class TrmInCardClientService {
@Autowired
TrmInCardClientDBRepository trmInCardClientDBRepository;
@Autowired
TrmInCardClientUKMRepository trmInCardClientUKMRepository;
private Logger log = Logger.getLogger(TrmInCardClientService.class.getName());
public TrmInCardClientService() {
}
@Scheduled(
fixedRate = 300000
)
public void updatelist() {
this.log.info("TrmInCardClient data transfer start");
try {
Iterable<TrmInCardClientUKM> trmInCardClientUKMS = this.trmInCardClientUKMRepository.findByDeleted(0);
List<TrmInCardClientUKM> trmInCardClientUKMList = new ArrayList();
List<TrmInCardClientDB> trmInCardClientDBList = new ArrayList<>();
Iterator var5 = trmInCardClientUKMS.iterator();
while (var5.hasNext()) {
TrmInCardClientUKM cardClientUKM = (TrmInCardClientUKM) var5.next();
trmInCardClientUKMList.add(cardClientUKM);
trmInCardClientDBList.add(new TrmInCardClientDB(cardClientUKM.getCard(), cardClientUKM.getClient(),
cardClientUKM.getDeleted(), cardClientUKM.getGlobal_id(), cardClientUKM.getVersion()));
}
this.trmInCardClientDBRepository.saveAll(trmInCardClientDBList);
this.log.info("TrmInCardClient data transfer end");
}
catch (Exception e) {
this.log.warning("Error encountered during TrmInCardClient data migration");
}
}
}