[Opensymphony-oscache] Error in mass concurrence!

hgwnet <[email protected]> Thu, 14 Apr 2005 17:55:13 CDT
Newsgroups gmane.comp.java.open-symphony.os-cache
Message-ID <24917045.1113519637802.JavaMail.os-j2ee@opensymphony01.contegix.com>
Just synchronize the method getFromCache(String key, int refreshPeriod, String cronExpiry) , although this whill decrease the performance.

Folllowing is my testing code:
[code]
  public void testMass() {
        for (int i = 0; i < 100; i++) {       //100 Threads
            new Thread(new Concurrence()).start();
        }
    }

class Concurrence implements Runnable {

        private int order = 0;

        public void run() {

            order = threadOrder++;

            int count = 1000;

           //System.out.println("Thread start >>>:" + order);

         
            for (int i = 0; i < count; i++) {
                  cache.put(String.valueOf(i), new Integer(i));
            }

            for (int i = 0; i < count; i++) {
                if (cache.get(String.valueOf(i)) != null) {
                    Assert.assertEquals(cache.get(String.valueOf(i)), new Integer(i));
                }
            }
              for (int i = 0; i < count; i++) {
                cache.remove(String.valueOf(i));
            }

            Assert.assertEquals(cache.size() , 0);
            Assert.assertEquals(cache.getCacheSize() , 0);
            Assert.assertEquals(cache.getCacheEntries(), 0);

            System.out.println("Test concurrent successfully!order:" + order);
        }
    }
[/code]

Notes:the "cache" in the code is my wrapped OSCache,just simple wrap method:getFromCache(String key, int refreshPeriod, String cronExpiry) .After set it synchronized,everything goes well.

---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=1556&messageID=4862#4862