相关文章推荐
笑点低的人字拖  ·  Math.random() - ...·  2 周前    · 
强悍的书签  ·  JavaScript 学习-34.HTML ...·  1 年前    · 
严肃的围巾  ·  pandas object转string-掘金·  1 年前    · 
傲视众生的烈酒  ·  sql ...·  2 年前    · 

问题描述:

xxljob定时任务中写了一个线程池,每次调用定时任务,都会起7条线程,进行数据传输,程序运行时报错:
java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.

bug原因:

线程池中的子线程获取不到定时任务主线程的request信息

解决方法:

在定义线程池之前加入两行代码,设置request子线程共享

// 子线程request共享
ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
RequestContextHolder.setRequestAttributes(sra, true);
// 定义线程池名称
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
                .setNameFormat("my-pool-%d").build();
//创建线程池
ThreadPoolExecutor blockchainSavePool = new ThreadPoolExecutor(
                TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(10),
                namedThreadFactory);
                    问题描述:xxljob定时任务中写了一个线程池,每次调用定时任务,都会起7条线程,进行数据传输,程序运行时报错:java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attribubug原因:线程池中的子线程获取不到定时任务主线程的request信息解决方法:在定义线程池之前加入两行代码,设置request子线程共享// 子线程request共享ServletRe
				
No thread-bound request found: " + "Are you referring to request attributes outside of an actual web request, " + "or processing a request outside of the originally receiving thread?
解决No thread-bound request found: Are you referring to request attributes outside of an actual web re
在开启新线程之前,将servletRequestAttributes设置为子线程共享 ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes(); //设置子线程共 RequestContextHolder.setRequestAttributes(servletRequestAttributes,true); 如果非we
java.lang.illegalstateexception: no thread-bound request found: are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? if you are actually operating within a web request and still receive this message, your code is probably running outside of dispatcherservlet: in this case, use requestcontextlistener or requestcontextfilter to expose the current request.
spring注解@Configuration、@Bean、@Autowired、@Controller、@Service、@Component、@Repository、@Value leinchu: 简单详细! 阿里云服务器下jupyter notebook 远程访问,已解决OSError: [Errno 99]Cannot assign requested address等问题 Osiris_sir: 不行啊,还是没用 mybatis-plus 实现一对多查询,返回VO对象某个字段为List qq_29320261: 这不行,分页直接gg mybatis-plus 实现一对多查询,返回VO对象某个字段为List Systemd: 是mybatis-plus,不过一对多涉及多表结果映射的查询没法直接用service自带方法或者queryWapper实现,只能去xml里写映射关系 mybatis-plus 实现一对多查询,返回VO对象某个字段为List 马路上开飞机: 这不是mybatis-plus吧?