perf(商城): 架构优化

分离数据访问模块
master
hequan_waynaqua 4 years ago
parent 4f7be105ed
commit e61339e674

@ -15,6 +15,7 @@ import com.wayn.common.util.R;
import com.wayn.data.redis.manager.RedisCache;
import com.wayn.mobile.api.service.IHomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@ -41,19 +42,15 @@ public class IHomeServiceImpl implements IHomeService {
@Autowired
private IDiamondService iDiamondService;
@Autowired
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Override
public R getHomeIndexData() {
if (redisCache.existsKey(INDEX_DATA)) {
return redisCache.getCacheObject(INDEX_DATA);
}
R success = R.success();
ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(
10,
10,
0L,
TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(),
r -> new Thread(r, "首页线程"));
Callable<List<Banner>> bannerCall = () -> iBannerService.list(new QueryWrapper<Banner>().eq("status", 0).orderByAsc("sort"));
Callable<List<Diamond>> diamondCall = () -> iDiamondService.list(new QueryWrapper<Diamond>()
.orderByAsc("sort")
@ -72,10 +69,10 @@ public class IHomeServiceImpl implements IHomeService {
FutureTask<List<Diamond>> diamondTask = new FutureTask<>(diamondCall);
FutureTask<List<Goods>> newGoodsTask = new FutureTask<>(newGoodsCall);
FutureTask<List<Goods>> hotGoodsTask = new FutureTask<>(hotGoodsCall);
poolExecutor.submit(bannerTask);
poolExecutor.submit(diamondTask);
poolExecutor.submit(newGoodsTask);
poolExecutor.submit(hotGoodsTask);
threadPoolTaskExecutor.submit(bannerTask);
threadPoolTaskExecutor.submit(diamondTask);
threadPoolTaskExecutor.submit(newGoodsTask);
threadPoolTaskExecutor.submit(hotGoodsTask);
try {
success.add("bannerList", bannerTask.get());
success.add("categoryList", diamondTask.get());
@ -85,7 +82,7 @@ public class IHomeServiceImpl implements IHomeService {
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
} finally {
poolExecutor.shutdown();
threadPoolTaskExecutor.shutdown();
}
return success;
}

@ -11,15 +11,15 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* 线
* 线使
**/
@Configuration
public class ThreadPoolConfig {
// 核心线程池大小
private int corePoolSize = 50;
private int corePoolSize = 200;
// 最大可创建的线程数
private int maxPoolSize = 200;
private int maxPoolSize = 400;
// 队列最大长度
private int queueCapacity = 1000;

Loading…
Cancel
Save