DB db = new DB();\r
@SuppressWarnings("resource")\r
Connection conn = db.getConnection();\r
- PreparedStatement ps = conn.prepareStatement(SELECT_SQL);\r
- ps.setLong(1, from);\r
- ps.setLong(2, to);\r
- ResultSet rs = ps.executeQuery();\r
- while (rs.next()) {\r
- String id = rs.getString("PUBLISH_ID");\r
- int feed = rs.getInt("FEEDID");\r
- long etime = rs.getLong("EVENT_TIME");\r
- String type = rs.getString("TYPE");\r
- String fid = rs.getString("FEED_FILEID");\r
- long clen = rs.getLong("CONTENT_LENGTH");\r
- String date = sdf.format(new Date(getPstart(id)));\r
- String key = date + "," + feed;\r
- Counters c = map.get(key);\r
- if (c == null) {\r
- c = new Counters(date, feed);\r
- map.put(key, c);\r
+ try(PreparedStatement ps = conn.prepareStatement(SELECT_SQL)) {\r
+ ps.setLong(1, from);\r
+ ps.setLong(2, to);\r
+ try(ResultSet rs = ps.executeQuery()) {\r
+ while (rs.next()) {\r
+ String id = rs.getString("PUBLISH_ID");\r
+ int feed = rs.getInt("FEEDID");\r
+ long etime = rs.getLong("EVENT_TIME");\r
+ String type = rs.getString("TYPE");\r
+ String fid = rs.getString("FEED_FILEID");\r
+ long clen = rs.getLong("CONTENT_LENGTH");\r
+ String date = sdf.format(new Date(getPstart(id)));\r
+ String key = date + "," + feed;\r
+ Counters c = map.get(key);\r
+ if (c == null) {\r
+ c = new Counters(date, feed);\r
+ map.put(key, c);\r
+ }\r
+ c.addEvent(etime, type, id, fid, clen);\r
+ }\r
}\r
- c.addEvent(etime, type, id, fid, clen);\r
+\r
+ db.release(conn);\r
}\r
- rs.close();\r
- ps.close();\r
- db.release(conn);\r
} catch (SQLException e) {\r
e.printStackTrace();\r
}\r
logger.debug("Query time: " + (System.currentTimeMillis()-start) + " ms");\r
- try {\r
- PrintWriter os = new PrintWriter(outfile);\r
+ try (PrintWriter os = new PrintWriter(outfile)){\r
os.println("date,feedid,minsize,maxsize,avgsize,minlat,maxlat,avglat,fanout");\r
for (String key : new TreeSet<String>(map.keySet())) {\r
Counters c = map.get(key);\r
os.println(c.toString());\r
}\r
- os.close();\r
} catch (FileNotFoundException e) {\r
System.err.println("File cannot be written: "+outfile);\r
}\r