http请求所在线程如何跟线程池中的线程通信

peter20091001 2017-08-23 09:40:39
使用SpringMVC框架,在处理HTTP请求的方法中创建了一个线程,并向线程池提交了这个线程。

@Controller
public class CompanyController {
@Resource(name = "taskExecutor")
private TaskExecutor taskExecutor;
@RequestMapping("/search_company")
public void test1(HttpServletRequest request, HttpServletResponse response) throws IOException{
Map<String,Object> m = new HashMap<String,Object>();
String search = request.getParameter("search");
if(request.getParameter("already_showed_id") !=null) {
System.out.println(request.getParameter("already_showed_id"));
}
System.out.println(search);
List<Company> list = companyService.select("%"+search+"%");
response.setContentType("text/html;charset=utf-8");
if(list.size() == 0) {
m.put("result", 1);
response.getWriter().print(JSON.toJSONString(m));
GetListRunnable run = new GetListRunnable();
run.setSearch(search);
taskExecutor.execute(run);
}
}
}


<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<!-- 核心线程数 -->
<property name="corePoolSize" value="5" />
<!-- 最大线程数 -->
<property name="maxPoolSize" value="50" />
<!-- 队列最大长度 -->
<property name="queueCapacity" value="1000" />
<!-- 线程池维护线程所允许的空闲时间,默认为60s -->
<property name="keepAliveSeconds" value="60" />
</bean>

在GetListRunnable线程运行过程中获取到一些数据,如何让http请求所在的线程也获取到这些数据?
求高手指教!分不够可以再加!
...全文
120 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧