package com.chenyang.nse.bussiness.init;

import com.chenyang.nse.bussiness.bean.DataCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Component
public class DataSourceInit implements ApplicationRunner {
   @Autowired
   DataCache dataCache;

   public void run(ApplicationArguments args) throws Exception {
      try {
         System.out.println("开始缓存数据源");
         (new Thread(() -> {
            try {
               this.dataCache.cacheData();
            } catch (InterruptedException e) {
               e.printStackTrace();
            }

         })).start();
         System.out.println("结束缓存数据源");
      } catch (Exception e) {
         e.printStackTrace();
      }

   }
}
