1煌集、SpringCloud-feign
@FeignClient(value = "book-auth-service", fallback = AuthFallBackService.class)
public interface AuthService {
@GetMapping("/auth/authorities")
ResJson<Set<String>> getAuthorities(@RequestParam("loginName") String loginName);
@GetMapping("/auth/validateJwtToken")
ResJson<Boolean> validateJwtToken(@RequestParam("token") String token);
@GetMapping("/auth/getLoginName")
ResJson<String> getUserLoginNameByToken(@RequestParam("token") String token);
@GetMapping("/auth/authuser")
ResJson<String> authUser(@RequestParam("token") String token);
}
@FeignClient(value = "book-auth-service", fallback = AuthFallBackService.class)
調(diào)用遠程服務(wù)
value:為注冊到Eureka中的服務(wù)名稱
fallback:解決調(diào)用的服務(wù)不可用時(使用hytrix)苫纤,返回自定義的值,避免出現(xiàn)服務(wù)熔斷的情況放钦。
AuthFallBackService.class:是當(dāng)前接口的實現(xiàn)類恭金,其中根據(jù)業(yè)務(wù)需要,在實現(xiàn)方法中定義返回值横腿。
2耿焊、SpringBoot
@EnableTransactionManagement
@SpringBootApplication(exclude = {JacksonAutoConfiguration.class})
@MapperScan("com.herokuCenter.mapper")
@EnableScheduling
public class HerokuCenterApplication {
public static void main(String[] args) throws IOException {
String env = StringUtils.isEmpty(System.getenv("ENV")) ? "uat" : System.getenv("ENV");
env = "uat";
System.out.println("==========當(dāng)前環(huán)境是:" + env + ", 啟動的配置文件是:application-" + env + ".properties");
Properties properties = new Properties();
InputStream in = HerokuCenterApplication.class.getClassLoader().getResourceAsStream("application-" + env + ".properties");
properties.load(in);
SpringApplication application = new SpringApplication(HerokuCenterApplication.class);
application.setDefaultProperties(properties);
application.run(args);
}
}
@SpringBootApplication
使用該注解實現(xiàn)springboot項目的自動裝配以及啟動
3、代碼
public String CreateCouponByDMP() {
//省略部分代碼
String tableName = isFirst.equals("0") ? batch : promCode;
try {
tempCouponMapper.createTableBatch("dmp." + "\"" + tableName + "\"");
logger.info("dmp." + "\"" + tableName + "\"" + "創(chuàng)建表格成功");
} catch (Exception e) {
e.printStackTrace();
logger.info("dmp." + "\"" + tableName + "\"" + "表格創(chuàng)建失敗");
}
logger.info("授權(quán)");
tempCouponMapper.grantToDMP(dmpPGUserName);
if (isFirst.equals("0")) {
Map map = new HashMap();
map.put("promCode", promCode);
map.put("isfirst", isFirst);
map.put("batch", batch);
map.put("tablename", "dmp." + "\"" + batch + "\"");
map.put("tablenamepro", "dmp." + "\"" + promCode + "\"");
Integer selectCount = 0;
String content = "處理成功";
try {
tempCouponMapper.insertTempCouponSec(map);
selectCount = tempCouponMapper.selectCount("dmp." + "\"" + batch + "\"", batch);
} catch (Exception e) {
logger.info("isfirst=0;batch={};promCode={};處理異常", batch, promCode);
content = "處理異常";
e.printStackTrace();
}
Map<String, Object> map2 = new HashMap<>();
map2.put("batchId", tempPromotionDefinition.getBatch());
map2.put("endCouponTime", new Date());
map2.put("couponCount", selectCount.toString());
promotionTaskMapper.updateEndCoupon(map2);
notifyDMP(content, tempPromotionDefinition.getBatch(), promCode, selectCount.toString(), busType, "DMP00", keyType);
return "更新成功";
}
ExecutorService executorService = Executors.newFixedThreadPool(5);
for (int i = 0; i < threadAmount; i++) {
logger.info("多線程操作");
executorService.execute(new InsertThread(threadAmount, tempPromotionDefinition.getBatch(), i * btach, btach, promCode,
uuid, Count, total, busType, keyType, systemGuid, isFirst));
}
executorService.shutdown();
while (true) {
try {
if (executorService.awaitTermination(5, TimeUnit.SECONDS)) {
logger.info("------dmp-------:開始通知");
Integer selectCount = tempCouponMapper.selectCount("dmp." + "\"" + promCode + "\"", batch);
logger.info("------dmp-------{}", selectCount);
Map<String, Object> map = new HashMap<>();
map.put("batchId", tempPromotionDefinition.getBatch());
map.put("endCouponTime", new Date());
map.put("couponCount", selectCount.toString());
promotionTaskMapper.updateEndCoupon(map);
//創(chuàng)建表
notifyDMP("處理成功", tempPromotionDefinition.getBatch(), promCode, selectCount.toString(), busType, "DMP00", keyType);
logger.info("------dmp-------:通知成功");
memberGroupMapper.createRepeatTable(tempPromotionDefinition.getBatch());
memberGroupMapper.delteRepeat(tempPromotionDefinition.getBatch());
memberGroupMapper.insertMemberGroupRepeat();
break;
} else {
logger.info("線程池中還有線程線程钩杰,請等待。措左。避除。。");
}
} catch (Exception e) {
e.printStackTrace();
}
}
return "券生成成功";
}
代碼描述
代碼在業(yè)務(wù)上的優(yōu)點:根據(jù)狀態(tài)以及批次動態(tài)的創(chuàng)建表格凉逛,避免大量的數(shù)據(jù)積累后出現(xiàn)更新操作數(shù)據(jù)被鎖從而導(dǎo)致性能低下的情況赏壹,同時也避免第三方在進行拉數(shù)據(jù)的時候進行查詢的操作(創(chuàng)建臨時表格,根據(jù)批次數(shù)據(jù)全部拉闰蚪琛)指蚁。
性能上的優(yōu)點:采用線程池避免線程的重復(fù)構(gòu)建,同時使用shutdown()與awaitTermination(5, TimeUnit.SECONDS)的方法來判斷線程執(zhí)行情況稍坯,以及確定在全部執(zhí)行完成后通知第三方系統(tǒng)進行數(shù)據(jù)的拉取,保證數(shù)據(jù)的完整性瞧哟,同時保證性能。