场景:在使用sprintboot 编写接口时,由于接口本身请求很慢,加上需要在接口中穿插生成图片功能,导致接口更慢,此时,就要考虑在接口中嵌入线程,从而不影响主业务速度。
代码:
线程实体类:将你需要使用到的service,还有参数全部写进线程实体类中
/**
*
* @Description:生成婚姻图片线程实体类
* @Author:ay
* @Date:2020/9/17
*/
@Data
public class HunYinThreadBO {
BdcClfdjService bdcClfdjService;
CreatePictureService createPictureService;
private String pmid;
private String ywlx;
}
编写线程方法
private void createHunyinPic(String ywlx,String pmid) {
//存放service
if(ywlx.equals(DLDLType.GRCLZZZYDJ)){
hunYinThreadBO.setBdcClfdjService(bdcClfdjService);
hunYinThreadBO.setCreatePictureService(createPictureService);
}
hunYinThreadBO.setPmid(pmid);
hunYinThreadBO.setYwlx(ywlx);
HunYinThread