Skip to content

Commit

Permalink
chore: Virtual thread
Browse files Browse the repository at this point in the history
  • Loading branch information
satran004 committed Mar 8, 2024
1 parent ae394d7 commit a71e257
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cardanofoundation.ledgersync.account.storage.impl;

import com.bloxbean.cardano.yaci.store.account.AccountStoreProperties;
import com.bloxbean.cardano.yaci.store.common.executor.ParallelExecutor;
import com.bloxbean.cardano.yaci.store.common.util.ListUtil;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -30,6 +31,7 @@ public class AddressTxAmountStorageImpl implements AddressTxAmountStorage {
private final DSLContext dsl;
private final AccountStoreProperties accountStoreProperties;
private final PlatformTransactionManager transactionManager;
private final ParallelExecutor parallelExecutor;

private final AggrMapper aggrMapper = AggrMapper.INSTANCE;
private TransactionTemplate transactionTemplate;
Expand All @@ -51,7 +53,7 @@ public void save(List<AddressTxAmount> addressTxAmount) {

if (accountStoreProperties.isParallelWrite()) {
// transactionTemplate.execute(status -> {
ListUtil.partitionAndApplyInParallel(addressTxAmtEntities, accountStoreProperties.getPerThreadBatchSize(), this::doSave);
ListUtil.partitionAndApplyInParallel(addressTxAmtEntities, accountStoreProperties.getPerThreadBatchSize(), this::doSave, parallelExecutor.getVirtualThreadExecutor());
// return null;
// });
} else {
Expand Down Expand Up @@ -98,6 +100,7 @@ private void doSave(List<AddressTxAmountEntity> addressTxAmountEntities) {
dsl.batch(inserts).execute();
**/

transactionTemplate.execute(status -> {
dsl.batched(c -> {
for (var addressTxAmount : addressTxAmountEntities) {
c.dsl().insertInto(ADDRESS_TX_AMOUNT)
Expand Down Expand Up @@ -132,6 +135,8 @@ private void doSave(List<AddressTxAmountEntity> addressTxAmountEntities) {
.execute();
}
});
return null;
});

}

Expand Down

0 comments on commit a71e257

Please sign in to comment.