static Node alloc() { final int threshold = 2; int tryCnt = 0; while (true) { tryCnt++; Node n = pool.poll(); if (n == null) { return new Node(); } else { if (n.getRefCnt() > 0) { pool.add(n); if (tryCnt <= threshold) continue; else return new Node(); } else { if (n.next != null) n.next.decRefCnt(); n.init(); return n; } } } }
static void free(Node n) { pool.add(n); }