commons-io引起的ygc问题
今天接到任务,图片上传服务器的性能有问题,高峰期间YGC频率在2秒一次,维护应用的程序员诊断的原因是图片处理API有性能问题。
不管咋样,亲自看一把才是王道,jmap -dump出堆内存文件。
用Eclipse MAT打开一看,发现FileCleaningTracker这个对象占用了将近一半的堆内存。
查看了下代码,发现这个类是commons-io下用于追踪文件的一个方法引起的问题。方法如下:
/** * Run the reaper thread that will delete files as their associated * marker objects are reclaimed by the garbage collector. */ @Override public void run() { // thread exits when exitWhenFinished is true and there are no more tracked objects while (exitWhenFinished == false || trackers.size() > 0) { try { // Wait for a tracker to remove. Tracker tracker = (Tracker) q.remove(); // cannot return null trackers.remove(tracker); if (!tracker.delete()) { deleteFailures.add(tracker.getPath()); } tracker.clear(); } catch (InterruptedException e) { continue; } } } }