| 1 10 11 package net.sf.cache4j.perfomance.test; 12 13 import net.sf.cache4j.perfomance.ITest; 14 import net.sf.cache4j.perfomance.ICache; 15 16 import java.util.Random ; 17 18 24 25 public class GetPutRemove implements ITest { 26 private ICache _cache; 29 31 private static final String NAME = "GetPutRemove"; 32 33 private static Random RND = new Random (System.currentTimeMillis()); 34 private static int COUNT = 2000; 35 private static int[] KEYS = new int[COUNT]; 36 static{ 37 for (int i = 0; i <COUNT; i++) { 38 KEYS[i] = RND.nextInt(COUNT); 39 } 40 } 41 44 49 public void init(ICache cache) throws Exception { 50 _cache = cache; 51 for (int i = 0; i <KEYS.length; i++) { 52 Object key = String.valueOf(KEYS[i]); 53 _cache.put(key, key); 54 } 55 } 56 57 61 public void test() throws Exception { 62 63 for (int j = 0; j <1000; j++) { 64 65 for (int i = 0; i <KEYS.length; i++) { 66 Object key = String.valueOf(KEYS[i]); 67 Object obj = _cache.get(key); 68 if(obj==null){ 69 _cache.put(key, key); 70 } else { 71 _cache.remove(key); 72 } 73 } 74 75 } 76 77 } 78 79 82 public void destroy() { 83 _cache = null; 84 } 85 86 89 public String getTestName() { 90 return NAME; 91 } 92 93 } | Popular Tags |