Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.brotherc.aquant.common.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
* 东财行业同步专用执行器:单线程 + 容量为 1 的等待队列,所有触发来源(主同步链、Cookie 更新)
* 在此串行执行,保证任意时刻最多一轮东财同步,东财请求始终只来自这一个线程。
* 等待队列满时丢弃新触发并记日志——东财同步有水位断点续传,被丢弃的触发由下一轮触发补齐
*/
@Slf4j
@Configuration
public class AsyncConfig {

@Bean
public ThreadPoolTaskExecutor eastmoneySyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setThreadFactory(new CustomizableThreadFactory("eastmoney-sync-"));
executor.setThreadGroupName("eastmoney-sync");
executor.setCorePoolSize(1);
executor.setMaxPoolSize(1);
executor.setQueueCapacity(1);
executor.setKeepAliveSeconds(60);
executor.setAllowCoreThreadTimeOut(true);
executor.setDaemon(true);
executor.setRejectedExecutionHandler((runnable, target) ->
log.info("东财行业同步已在执行或排队中,忽略本次触发"));
return executor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,27 @@ public class StockIndustryBoardEmSyncService {
private final AtomicBoolean syncRunning = new AtomicBoolean(false);

/**
* Cookie 更新后自动触发的异步同步:独立线程执行,与调度链(task-1)上的其他数据同步并行,
* 不互相阻塞。水位校验与逐板块断点续传保证重复触发安全
* Cookie 更新后自动触发的异步同步:独立线程执行,与主同步链上的其他数据同步并行,
* 不互相阻塞。水位校验与逐板块断点续传保证重复触发安全。
* 与 {@link #triggerSynchronizeFromSchedule()} 共用 eastmoneySyncExecutor 单线程执行器,
* 两类触发相互排队,不会产生并发的东财同步
*/
@Async
@Async("eastmoneySyncExecutor")
public void triggerSynchronizeAfterCookieUpdate() {
log.info("东财会话 Cookie 已更新,异步触发行业同步(独立线程,与其他同步并行)");
synchronizeIfRequired(LocalDateTime.now());
}

/**
* 主同步链触发的异步同步:剥离到独立线程与 akshare 链并行,缩短整体同步耗时。
* 与 Cookie 触发共用单线程执行器串行排队,CAS 防重入兜底
*/
@Async("eastmoneySyncExecutor")
public void triggerSynchronizeFromSchedule() {
log.info("东财行业同步已异步触发(独立线程,与主同步链并行)");
synchronizeIfRequired(LocalDateTime.now());
}

public void synchronizeIfRequired(LocalDateTime now) {
if (!syncRunning.compareAndSet(false, true)) {
log.info("东方财富行业同步已在进行中,跳过本次触发");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public void onApplicationReady() {
private void syncStackDtaLatest() {
LocalDateTime now = LocalDateTime.now();

// 东财同步与 akshare 链无数据依赖(写独立的 _em 表,仅依赖自身水位和交易日历,
// 交易日历已在本方法调用前同步完成),剥离到专用单线程执行器与整条 akshare 链并行,
// 覆盖同花顺行业/成分股同步区间;网关侧的全局节流/重试/熔断保持不变
stockIndustryBoardEmSyncService.triggerSynchronizeFromSchedule();

log.info("同步股票行情数据开始");
syncStackQuote(now);
log.info("同步股票行情数据完成");
Expand All @@ -139,7 +144,6 @@ private void syncStackDtaLatest() {
log.info("同步股票板块数据开始");
syncStockBoard(now);
stockBoardConstituentSyncService.synchronizeAllIfRequired(now);
stockIndustryBoardEmSyncService.synchronizeIfRequired(now);
log.info("同步股票板块数据完成");

log.info("同步基金数据开始");
Expand Down
Loading