需要使用rxjava和hystrix在以下代码中提高性能

tcomlyy6  于 2021-07-14  发布在  Java
关注(0)|答案(0)|浏览(228)

我需要一个帮助,以提高性能在下面的代码与rxjava,hystrix和jdbctemplate。下面的代码需要20分钟来处理8000条记录,而且内存也有问题。我正在尝试从表中获取10万个产品id,并点击restapi获取产品的最新价格信息,并将记录插入db中的temp表中,并调用oracle过程对最新的价格值执行一些操作。注意:所有以命令结束的函数都是hystrix并返回可观察对象,此作业预计每天运行一次。

List<Price> PriceList = new ArrayList<>();
Map<String, String> errorSkus = new HashMap<>();
return Observable.zip(getErrProductsCommands, // error products from previous run
                getEligibleProductsCommands,// expected to return 100k product ids and returns List<String>
                (errProduct, eligiableProduct) -> {
                    LOGGER.info("inside zip ");
                    eligiableProduct.addAll(errProduct);
                    updateErrProductCommand(errProduct);// jdbctemplate batchupdate update as processed in error table.
                    LOGGER.info("eligiableProduct-->{}", eligiableProduct.size());
eligiableProduct.parallelStream().distinct().forEach( // using parallenStream but no improvement
                Product -> {
                    LOGGER.info("Product->{}", Product);

                    Price Price = priceExternalAPICommand(Product).queue().get();//each external API calls takes 2 secs
                    if (Price != null) {
                        PriceList.add(Price);
                    } else {
                        errorProduct.put(Product, "Not Found");
                    } 
                }
        )
                    return PriceList;
                })//zip ends
                .flatMap(i -> Observable.zip(insertErrTableCommand(errorSkus), // insert error product in error table of current run, jdbctemplate batchupdate
                            insertTmpTableCommand(PriceList), (err, stg) -> true))// insert in Temp table as jdbctemplate batchupdate expected products 1 lakh. returns true always
                    .flatMap(callProc -> callOracleProcCommand)
                    .doOnError(i -> {
                        LOGGER.info("doOnError -{0}", i.getCause());
                        (..send mail);
                    }).subscribeOn(Schedulers.newThread()).subscribe();

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题