on ‎2018 Jun 26 8:13 PM
I want to make saving to the db to be asynchronous using the example method below.
void save(final List<CustomerModel> customers,
final Map<String, List<CustomerProductsModel>> customerProducts) {
CompletableFuture.runAsync(new Runnable() {
@Override
public void run() {
// Save Customer + Products Aysnc
for(final CustomerModel customer : customers) {
for(final CustomerProductsModel product : customerProducts.get(customer.getUUID())) {
product.setEndDate(changeDateFormat(products.getEndDate()));
product.setStartDate(changeDateFormat(products.getStartDate()));
modelService.save(product);
}
modelService.save(customer);
}
}
});
}
However, nothing is saving at all.
Request clarification before answering.
Never mind I figured it out. Need specify an executor, pass it into the CompletableFuture and set the modelService from the bean inside the run() method
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could it be that you are not running it in a transaction? See if this could be of help . https://help.hybris.com/6.7.0/hcd/8c7387f186691014922080f2e053216a.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.