@Test @Ignore public void testConcurrency() throws InterruptedException { ParameterCacheConfig pcc = new ParameterCacheConfig(true, true, 1000, 4096); final ParameterCache pcache = new ParameterCacheImpl(pcc); Thread writer = new Thread(new Runnable() { @Override public void run() { long t0 = System.currentTimeMillis(); List<Parameter> plist = new ArrayList<Parameter>(); for(int i=2;i<numParam; i++) { plist.add(new Parameter("p"+i)); } for(long t=0; t<numWrites*10; t+=10) { ArrayList<ParameterValue> pvList = new ArrayList<ParameterValue>(); pvList.add(getUint64ParameterValue(p1,t)); for (int i=2; i<numParam; i++) { pvList.add(getUint64ParameterValue(plist.get(i-2),t)); } pcache.update(pvList); } long t1 = System.currentTimeMillis(); System.out.println("writer finished in "+(t1-t0)+" ms"); } }); writer.start(); Thread.sleep(100); CacheReader[] readers = new CacheReader[numReaders]; for(int i=0; i<numReaders;i++) { readers[i] = new CacheReader(i, pcache, p1); new Thread(readers[i]).start(); } writer.join(); long totalReadTime =0; for(CacheReader r:readers) { totalReadTime+=r.runningTime; } System.out.println("totalReadTime: "+totalReadTime); }
@Override public void update(Collection<ParameterValue> pvs) { ParameterValueList pvlist = new ParameterValueList(pvs); for (ParameterValue pv : pvs) { Parameter p = pv.getParameter(); CacheEntry ce = cache.get(p); if (ce == null) { if (cacheAll || parametersToCache.containsKey(p)) { ce = new CacheEntry(p, timeToCache, maxNumEntries); cache.put(p, ce); ce.add(pvlist); } } else { ce.add(pvlist); } } }
ParameterCacheImpl implements ParameterCache { @Override public void update(Collection<ParameterValue> pvs) { ParameterValueList pvlist = new ParameterValueList(pvs); for (ParameterValue pv : pvs) { Parameter p = pv.getParameter(); CacheEntry ce = cache.get(p); if (ce == null) { if (cacheAll || parametersToCache.containsKey(p)) { ce = new CacheEntry(p, timeToCache, maxNumEntries); cache.put(p, ce); ce.add(pvlist); } } else { ce.add(pvlist); } } } }
ParameterCacheImpl implements ParameterCache { @Override public void update(Collection<ParameterValue> pvs) { ParameterValueList pvlist = new ParameterValueList(pvs); for (ParameterValue pv : pvs) { Parameter p = pv.getParameter(); CacheEntry ce = cache.get(p); if (ce == null) { if (cacheAll || parametersToCache.containsKey(p)) { ce = new CacheEntry(p, timeToCache, maxNumEntries); cache.put(p, ce); ce.add(pvlist); } } else { ce.add(pvlist); } } } ParameterCacheImpl(ParameterCacheConfig cacheConfig); }
ParameterCacheImpl implements ParameterCache { @Override public void update(Collection<ParameterValue> pvs) { ParameterValueList pvlist = new ParameterValueList(pvs); for (ParameterValue pv : pvs) { Parameter p = pv.getParameter(); CacheEntry ce = cache.get(p); if (ce == null) { if (cacheAll || parametersToCache.containsKey(p)) { ce = new CacheEntry(p, timeToCache, maxNumEntries); cache.put(p, ce); ce.add(pvlist); } } else { ce.add(pvlist); } } } ParameterCacheImpl(ParameterCacheConfig cacheConfig); @Override void update(Collection<ParameterValue> pvs); @Override List<ParameterValue> getValues(List<Parameter> plist); @Override ParameterValue getLastValue(Parameter p); @Override List<ParameterValue> getAllValues(Parameter p); @Override List<ParameterValue> getAllValues(Parameter p, long start, long stop); @Override void clear(); }
ParameterCacheImpl implements ParameterCache { @Override public void update(Collection<ParameterValue> pvs) { ParameterValueList pvlist = new ParameterValueList(pvs); for (ParameterValue pv : pvs) { Parameter p = pv.getParameter(); CacheEntry ce = cache.get(p); if (ce == null) { if (cacheAll || parametersToCache.containsKey(p)) { ce = new CacheEntry(p, timeToCache, maxNumEntries); cache.put(p, ce); ce.add(pvlist); } } else { ce.add(pvlist); } } } ParameterCacheImpl(ParameterCacheConfig cacheConfig); @Override void update(Collection<ParameterValue> pvs); @Override List<ParameterValue> getValues(List<Parameter> plist); @Override ParameterValue getLastValue(Parameter p); @Override List<ParameterValue> getAllValues(Parameter p); @Override List<ParameterValue> getAllValues(Parameter p, long start, long stop); @Override void clear();  }