近日Code

@Bean("自定义线程池名称")
    public ThreadPoolTaskExecutor saveDataExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        //核心线程数目
        executor.setCorePoolSize(10);
        //队列中最大的数目
        executor.setQueueCapacity(200);
        //指定最大线程数
        executor.setMaxPoolSize(15);
        //线程名称前缀
        executor.setThreadNamePrefix("线程名字");
        //rejection-policy:当pool已经达到max size的时候,如何处理新任务
        //CALLER_RUNS:不在新线程中执行任务,而是由调用者所在的线程来执行
        //对拒绝task的处理策略
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        //线程空闲后的最大存活时间(对核心线程不起作用)
        executor.setKeepAliveSeconds(60);
        //过期时间对核心线程起作用
        //executor.setAllowCoreThreadTimeOut(true);
        //加载
        executor.initialize();
        return executor;
    }
	@Async("自定义线程池名称")
	public Future<Boolean> save(String functionName, String tableName, List<Object> list);

Oracle判断表是否存在

    <select id="hasTableInDatabase" resultType="java.lang.Integer">
        select count(*) from user_tables t where table_name= upper('${tableName}')
    </select>

    <update id="createTable">
        create table ${tableName} as SELECT * FROM ${baseTableName} where 1=2
    </update>

反射调用mapper所有方法

@Autowired
	private SqlSession sqlSession;

	@Override
	public Future<Boolean> save(String functionName, String tableName, List<Object> list) {
		try {
			// 获取Mapper地址
			Class<?> mapper = Class
					.forName("xxxMapper");
			Object instance = Proxy.newProxyInstance(mapper.getClassLoader(), new Class[] { mapper },
					new DataCollectInvocationHandler(sqlSession.getMapper(mapper)));
			// 各自的接口中需要定义好对应的方法才能调用
			Method method = instance.getClass().getMethod(functionName, String.class, List.class);
			method.invoke(instance, tableName, list);
			return new AsyncResult<>(true);
		} catch (Exception e) {
			e.printStackTrace();
			return new AsyncResult<>(false);
		}
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值