其实线程池不见得比你的慢慢获取数据快多少
是用分页做了。页面用ajax无刷新实现数据加载,但是页面多显示js代码或是动态的填充层,这样不利于蜘蛛的抓取。改用了页面跳转的时候在action中加载数据,然后跳转至页面,不过这样速度比较慢,在action中加了一个线程池效果还是不太理想,怎么办???
/* 多线程从多个接口获取查询数据 */ ExecutorService pool = Executors.newFixedThreadPool(1); //创建线程池 Callable<List> rmCallable = new RoadRunCallable(criteria,SqlConstants.GET_TRAVELS_LIST); Future<List> rmfuture = pool.submit(rmCallable); pool.shutdown(); //关闭线程池 public class RoadRunCallable implements Callable<List> { private PageQueryCriteria critria; private String statementName; public RoadRunCallable(PageQueryCriteria critria,String statementName){ this.critria = critria; this.statementName = statementName; } @Override public List call() throws Exception { Query query = (Query)ServiceLocator.getService("query"); return query.queryForList(statementName, critria); } }
问题解决了,我在action中用到了线程池,解决页面跳转过慢的问题。
81,091
社区成员
341,719
社区内容
加载中
试试用AI创作助手写篇文章吧