Problems with PojoCache to work and outOfMemory
yudivian Sep 1, 2006 8:39 PMI have two problems using PojoCache. I have an application tha use PojoCache to replicate data, but when I run the application in one node it seems to work fine but when the time pass I got an OutOfMemory Exception and I don't know why. The other problem is that I can't run fine the application in more than one node. This is the code I use, and the application call the methods putMessage and getMessage all the time. I appreciate any help on this.
This is the code
public class JBCacheDMS { private static final Logger log = Logger.getLogger(JBCacheDMS.class); protected boolean inited; protected PojoCache queues; protected HashMap<String, List> proxyQueues; public void init(String DMSUrl, String[] DMSnodesUrls) { try { queues = new PojoCache(); PropertyConfigurator config = new PropertyConfigurator(); // configure tree cache. config.configure(queues, "config/replSyncPC-service.xml"); String platformName = System.getProperty("platformName"); queues.setClusterName("DMS-" + platformName); queues.setCacheMode(PojoCache.REPL_SYNC); queues.createService(); queues.startService(); // addTreeCacheListener(); proxyQueues = new HashMap<String, List>(); inited = true; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * To add a TreeCacheListener * * @param listener * The listener to add */ public void addTreeCacheListener(TreeCacheListener listener) { queues.addTreeCacheListener(listener); } /** * To remove a TreeCacheListener * * @param listener * The listener to remove */ public void removeTreeCacheListener(TreeCacheListener listener) { queues.removeTreeCacheListener(listener); } /** * Return an instance of DMStorage(the class itself) if the class was * inited, if not returns null * * @return an instance of DMS */ public DMS getDMS() { if (inited) return this; return null; } public void stop() { // TODO Auto-generated method stub } public void createQueue(String name) { try { queues.putObject(name, new ArrayList<AbstractMessage>()); List<AbstractMessage> proxyList = (List) queues.getObject(name); proxyQueues.put(name, proxyList); // System.out.println(getAgent(name).getName().getName()); } catch (CacheException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void deleteQueue(String name) { try { proxyQueues.remove(name); queues.removeObject(name); queues.remove(name); } catch (CacheException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void putMessage(String name, AbstractMessage message) { if (!queues.exists(name)){ createQueue(name); } List<AbstractMessage> proxyList = proxyQueues.get(name); proxyList.add(message); } public AbstractMessage getMessageBusy(String name) { if (!queues.exists(name)){ createQueue(name); } List<AbstractMessage> proxyList = proxyQueues.get(name); AbstractMessage message = proxyList.remove(0); while(message == null){ message = proxyList.remove(0); try { Thread.sleep(10); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return message; }