How can i interrupt the updateRecords Transactional method using another method.
Both methods requires from rest api.
<code>@Transactional
public void updateRecords() {
List<Record> all = repository.findAll();
all.forEach(r -> r.setStatus(RecordType.IN_PROGRESS));
IntStream.range(0, all.size())
.forEach(i -> {
try {
Thread.sleep(2000);
repository.save(all.get(i));
log.info("RecordServiceImpl.updateRecords() = {}", all.get(i));
} catch (InterruptedException e) {
log.info("interrupted");
throw new RuntimeException(e);
}
});
}
public void interrupt() {
}
</code>
<code>@Transactional
public void updateRecords() {
List<Record> all = repository.findAll();
all.forEach(r -> r.setStatus(RecordType.IN_PROGRESS));
IntStream.range(0, all.size())
.forEach(i -> {
try {
Thread.sleep(2000);
repository.save(all.get(i));
log.info("RecordServiceImpl.updateRecords() = {}", all.get(i));
} catch (InterruptedException e) {
log.info("interrupted");
throw new RuntimeException(e);
}
});
}
public void interrupt() {
}
</code>
@Transactional
public void updateRecords() {
List<Record> all = repository.findAll();
all.forEach(r -> r.setStatus(RecordType.IN_PROGRESS));
IntStream.range(0, all.size())
.forEach(i -> {
try {
Thread.sleep(2000);
repository.save(all.get(i));
log.info("RecordServiceImpl.updateRecords() = {}", all.get(i));
} catch (InterruptedException e) {
log.info("interrupted");
throw new RuntimeException(e);
}
});
}
public void interrupt() {
}
I have tried throwing exception from interrupt() method but it doesnt work and i dont need Exception in my stack trace. And i tried put @Transactional(propagation = Propagation.REQUIRES_NEW) on interrupt() method but it again doesnt work.