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.