DataSource dataSource = new HikariDataSource(config); try (Connection connection = dataSource.getConnection()) { // ... } @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void processBatch(List<Item> items) { // ... } CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder() .withCache("batchCache", CacheConfigurationBuilder.newCacheConfigurationBuilder(YourKey.class, YourValue.class).build()) .build(true); Cache<YourKey, YourValue> cache = cacheManager.getCache("batchCache", YourKey.class, YourValue.class); YourValue value = cache.get(key); if (value == null) { value = getDataFromDatabase(); cache.put(key, value); } ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); List<Future<Result>> futures = new ArrayList<>(); for (Task task : tasks) { Future<Result> future = executorService.submit(task); futures.add(future); } for (Future<Result> future : futures) { Result result = future.get(); // ... } executorService.shutdown();


上一篇:
下一篇:
切换中文