关于若依AsyncFactory的一些思考,记录一下

类比观星台项目业务:字段数据量都比较大,但需要都保存,但计算只需要其中三列数据,因此需要纵向分表

第一步:导入大批量数据,利用load data先导入数据

第二部:导入成功后,通过单独线程将导入数据纵向分表,添加线程通过后台直接将数据二次入库

若依操作日志入库如下:

 /**
     * 操作日志记录
     *
     * @param operLog 操作日志信息
     * @return 任务task
     */
    public static TimerTask recordOper(final SysOperLog operLog)
    {
        return new TimerTask()
        {
            @Override
            public void run()
            {
                // 远程查询操作地点
                operLog.setOperLocation(AddressUtils.getRealAddressByIP(operLog.getOperIp()));
                SpringUtils.getBean(ISysOperLogService.class).insertOperlog(operLog);
            }
        };
    }

在aop中调用

AsyncManager.me().execute(AsyncFactory.recordOper(operLog));

代码

 
/**
     * 操作延迟10毫秒
     */
    private final int OPERATE_DELAY_TIME = 10;

    /**
     * 异步操作任务调度线程池
     */
    private ScheduledExecutorService executor = SpringUtils.getBean("scheduledExecutorService");

/**
     * 执行任务
     *
     * @param task 任务
     */
    public void execute(TimerTask task)
    {
        executor.schedule(task, OPERATE_DELAY_TIME, TimeUnit.MILLISECONDS);
    }

 

posted on 2023-05-09 16:04  大山008  阅读(186)  评论(0编辑  收藏  举报