|
@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.transaction.PlatformTransactionManager; |
|
|
import org.springframework.transaction.PlatformTransactionManager; |
|
|
import org.springframework.transaction.TransactionDefinition; |
|
|
import org.springframework.transaction.TransactionDefinition; |
|
|
import org.springframework.transaction.TransactionStatus; |
|
|
import org.springframework.transaction.TransactionStatus; |
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.support.DefaultTransactionDefinition; |
|
|
import org.springframework.transaction.support.DefaultTransactionDefinition; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
@ -28,7 +29,7 @@ public class TransationDemo { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private PlatformTransactionManager txManager; |
|
|
private PlatformTransactionManager txManager; |
|
|
|
|
|
|
|
|
// @Transactional
|
|
|
@Transactional |
|
|
public void creteTask(JSONArray request){ |
|
|
public void creteTask(JSONArray request){ |
|
|
|
|
|
|
|
|
List<TransactionStatus> statusCollent = new ArrayList<>(); |
|
|
List<TransactionStatus> statusCollent = new ArrayList<>(); |
|
@ -71,7 +72,7 @@ public class TransationDemo { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//封装参考
|
|
|
|
|
|
class TransactionManagerUtil{ |
|
|
class TransactionManagerUtil{ |
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
public static void main(String[] args) { |
|
@ -96,6 +97,10 @@ class TransactionManagerUtil{ |
|
|
PlatformTransactionManager txManager = null; //SpringContextHolder.getBean(PlatformTransactionManager.class);
|
|
|
PlatformTransactionManager txManager = null; //SpringContextHolder.getBean(PlatformTransactionManager.class);
|
|
|
Map<String, TransactionStatus> statusMap = new HashMap<>(); |
|
|
Map<String, TransactionStatus> statusMap = new HashMap<>(); |
|
|
List<TransactionStatus> errTask; |
|
|
List<TransactionStatus> errTask; |
|
|
|
|
|
|
|
|
|
|
|
DefaultTransactionDefinition init = new DefaultTransactionDefinition(); |
|
|
|
|
|
init.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); |
|
|
|
|
|
TransactionStatus initStatus = txManager.getTransaction(init); |
|
|
try { |
|
|
try { |
|
|
//创建所有事务集合
|
|
|
//创建所有事务集合
|
|
|
Consumer<String> allTransactionConsumer = task -> { |
|
|
Consumer<String> allTransactionConsumer = task -> { |
|
@ -122,6 +127,7 @@ class TransactionManagerUtil{ |
|
|
txManager.commit(value); |
|
|
txManager.commit(value); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
txManager.commit(initStatus); |
|
|
} |
|
|
} |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|