67,513
社区成员
发帖
与我相关
我的任务
分享
public List<Device> findByPlatform(int platform) {
String key = "platform-device-"+platform;
List<Device> devices = (List<Device>) RedisClient.getObject(key);
if(devices == null){
String sql = "select udid,token,country,language,platform,osVersion from device_info where platform=?";
devices = (List<Device>) jdbcTemplate.query(sql, new Object[]{platform}, new DeviceMapper());
//这句执行很慢,数据库里面总共100W数据,查询出来大概有50W条数据,数据库执行时间大概2-3s,
//求解为什么在程序里面执行这么慢?
}
return devices;
}
dbcTemplate.query(sql, new Object[]{platform}, new ResultSetExtractor<List<Device>>() {
@Override
public List<Device> extractData(ResultSet rs) throws SQLException, DataAccessException {
rs.last();
int row = rs.getRow();
List<Device> devices = new ArrayList<Device>(row+10);
rs.beforeFirst();
Device device;
//while循环里面非常慢,前面执行都很快
while (rs.next()) {
device = new Device();
device.setUdid(rs.getString("udid"));
device.setCountry(rs.getString("country"));
device.setLanguage(rs.getString("language"));
device.setOsVersion(rs.getString("osVersion"));
device.setPlatform(rs.getInt("platform"));
device.setToken(rs.getString("token"));
devices.add(device);
}
return devices;
}