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

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

Loading…
Cancel
Save