1 14 package org.aspectj.runtime.internal.cflowstack; 15 16 import java.util.Enumeration ; 17 import java.util.Hashtable ; 18 import java.util.Stack ; 19 20 public class ThreadStackImpl11 implements ThreadStack { 21 private Hashtable stacks = new Hashtable (); 22 private Thread cached_thread; 23 private Stack cached_stack; 24 private int change_count = 0; 25 private static final int COLLECT_AT = 20000; 26 private static final int MIN_COLLECT_AT = 100; 27 28 public synchronized Stack getThreadStack() { 29 if (Thread.currentThread() != cached_thread) { 30 cached_thread = Thread.currentThread(); 31 cached_stack = (Stack )stacks.get(cached_thread); 32 if (cached_stack == null) { 33 cached_stack = new Stack (); 34 stacks.put(cached_thread, cached_stack); 35 } 36 change_count++; 37 int size = Math.max(1, stacks.size()); if (change_count > Math.max(MIN_COLLECT_AT, COLLECT_AT/size)) { 40 Stack dead_stacks = new Stack (); 41 for (Enumeration e = stacks.keys(); e.hasMoreElements(); ) { 42 Thread t = (Thread )e.nextElement(); 43 if (!t.isAlive()) dead_stacks.push(t); 44 } 45 for (Enumeration e = dead_stacks.elements(); e.hasMoreElements(); ) { 46 Thread t = (Thread )e.nextElement(); 47 stacks.remove(t); 48 } 49 change_count = 0; 50 } 51 } 52 return cached_stack; 53 } 54 55 } 56 | Popular Tags |