Re: [collections] LRUMap Problem ConcurrentModificationException
Hi, I'm using the one from the map package my import looks like this: import org.apache.commons.collections.map.LRUMap; As I've seen the LRUMap outside the map package is deprecated. René 2009/6/15 Leon Rosenberg rosenberg.l...@googlemail.com: weird enough there are two LRUMap classes in commons collections, org.apache.commons.collections and org.apache.commons.collections.map. Which one are you using? regards Leon On Mon, Jun 15, 2009 at 6:00 PM, Renè Glanzerrene.glan...@gmail.com wrote: Yes of course, the code with the time based cache systems was set up with an ordniary HashMap. But when rapidly seach requests are generated the time based mechanism fails to delete old entries - cause they are not old enough - and so the cache will raise up until the entire VM memory is used. Then i found the LRUMap switched to it and bang Exception in my delete method. When i switch back to HashMap the code runs well - as currently on the productive system - except the open memory leak. René 2009/6/15 Leon Rosenberg rosenberg.l...@googlemail.com: just out of curiosity have you tried the same code with a standard hashmap? Leon On Mon, Jun 15, 2009 at 4:37 PM, Renè Glanzerrene.glan...@gmail.com wrote: Hello, side note accepted :-) In my class I checked the get, put and remove methods. All are synchronized. As you can see also the code which wants to delete the elements is synchronized. So I've no clue where the ConcurrentModificationException is comming from :-( Thanks René 2009/6/15 Leon Rosenberg rosenberg.l...@googlemail.com: Hello, on a side note, generics make reading of code easier :-) you haven't posted the whole code, but have you (double)checked that all other acesses to store are synchronized? regards Leon On Mon, Jun 15, 2009 at 2:31 PM, Renè Glanzerrene.glan...@gmail.com wrote: I'm calling the remove() method on the iterator. I know when i call the remove on the map itself it will cause the problem with my currently running iterator, but i'm aware of that. Here is the code block which should delete old entries: store: is the LRUMap birth: is a long which keeps the creation time when this is set to 0 the item should be deleted public void removeAllExpiredItems() { synchronized(this.store) { Iterator it=this.store.keySet().iterator(); while(it.hasNext()) { Object key=it.next(); Object o=this.get(key); if(o != null) { Item iEntry=(Item)this.store.get(key); if(iEntry.birth==0) it.remove(); //Here the exception occurs } } this.setLastCleanDate(new Date()); //only to know when the deleter run the last time } } Thanks for any help :-) René 2009/6/15 James Carman ja...@carmanconsulting.com: Are you calling remove() on the iterator or on the map itself? On Mon, Jun 15, 2009 at 6:37 AM, Renè Glanzerrene.glan...@gmail.com wrote: Hello, is there still no help for me? Is somebody able to explain me, why i get this java.util.ConcurrentModificationException on iterating and calling remove() on the LRUMap? Please René 2009/6/10 Renè Glanzer rene.glan...@gmail.com: Hello Ted, thanks for the fast response. I understand that simultaneously puts and gets do not cause the exception cause they are synchronized in my class. And my stated code-fragment is the part which wants to delete the entries from the underlying LRUMap. And my code is wrapped in the synchronized block. But i think the LRUMap herselfe also iterates the entries and this maybe happens at the same time when my iterator is checking and trying to delete elements. My class is not implementing the LRUMap but has one LRUMap as a variable. So your solution to override the removeLRU(Entry) methode would not help meunfortunatelly :-( For now i really do not know how to solve the problem in an easy way without refractoring the entire code? Any other solutions? Thanks René 2009/6/9 Ted Dunning ted.dunn...@gmail.com: I apologize for not reading your thread with great care, but I think that your problem is pretty clear. The issue is not to do with gets and puts overlapping. The issue is that a put or remove happened during the life of your iterator. One way to avoid this is to synchronize the entire method that does the deletion of old elements. To speed that up, you might just synchronize the scan for elements to delete and collect them into a list. Then you can delete them outside the loop. Since your scan is probably pretty fast, this may be sufficient. With very high levels of updates and threading, it would cause problems. Another option is to clone the table. I believe that some implementations of LRUMap in Lucene do copy-on-write semantics, but I don't think that collections has these. Without that, cloning will be as slow or slower than your scan so the first option would be better. I am curious,
Re: [collections] LRUMap Problem ConcurrentModificationException
Hey Otis, i found this one: https://issues.apache.org/jira/browse/COLLECTIONS-3 but there is no solutions only an assumption at the end of the thread?? René 2009/6/15 Otis Gospodnetic otis_gospodne...@yahoo.com: Btw. I think you'll find a report about this from a few years ago in the Collections JIRA. Just search for my name. Otis -- Sematext -- http://sematext.com/ -- Lucene - Solr - Nutch - Original Message From: Renè Glanzer rene.glan...@gmail.com To: Commons Users List user@commons.apache.org Sent: Monday, June 15, 2009 12:00:54 PM Subject: Re: [collections] LRUMap Problem ConcurrentModificationException Yes of course, the code with the time based cache systems was set up with an ordniary HashMap. But when rapidly seach requests are generated the time based mechanism fails to delete old entries - cause they are not old enough - and so the cache will raise up until the entire VM memory is used. Then i found the LRUMap switched to it and bang Exception in my delete method. When i switch back to HashMap the code runs well - as currently on the productive system - except the open memory leak. René 2009/6/15 Leon Rosenberg : just out of curiosity have you tried the same code with a standard hashmap? Leon On Mon, Jun 15, 2009 at 4:37 PM, Renè Glanzerwrote: Hello, side note accepted :-) In my class I checked the get, put and remove methods. All are synchronized. As you can see also the code which wants to delete the elements is synchronized. So I've no clue where the ConcurrentModificationException is comming from :-( Thanks René 2009/6/15 Leon Rosenberg : Hello, on a side note, generics make reading of code easier :-) you haven't posted the whole code, but have you (double)checked that all other acesses to store are synchronized? regards Leon On Mon, Jun 15, 2009 at 2:31 PM, Renè Glanzerwrote: I'm calling the remove() method on the iterator. I know when i call the remove on the map itself it will cause the problem with my currently running iterator, but i'm aware of that. Here is the code block which should delete old entries: store: is the LRUMap birth: is a long which keeps the creation time when this is set to 0 the item should be deleted public void removeAllExpiredItems() { synchronized(this.store) { Iterator it=this.store.keySet().iterator(); while(it.hasNext()) { Object key=it.next(); Object o=this.get(key); if(o != null) { Item iEntry=(Item)this.store.get(key); if(iEntry.birth==0) it.remove(); //Here the exception occurs } } this.setLastCleanDate(new Date()); //only to know when the deleter run the last time } } Thanks for any help :-) René 2009/6/15 James Carman : Are you calling remove() on the iterator or on the map itself? On Mon, Jun 15, 2009 at 6:37 AM, Renè Glanzer wrote: Hello, is there still no help for me? Is somebody able to explain me, why i get this java.util.ConcurrentModificationException on iterating and calling remove() on the LRUMap? Please René 2009/6/10 Renè Glanzer : Hello Ted, thanks for the fast response. I understand that simultaneously puts and gets do not cause the exception cause they are synchronized in my class. And my stated code-fragment is the part which wants to delete the entries from the underlying LRUMap. And my code is wrapped in the synchronized block. But i think the LRUMap herselfe also iterates the entries and this maybe happens at the same time when my iterator is checking and trying to delete elements. My class is not implementing the LRUMap but has one LRUMap as a variable. So your solution to override the removeLRU(Entry) methode would not help meunfortunatelly :-( For now i really do not know how to solve the problem in an easy way without refractoring the entire code? Any other solutions? Thanks René 2009/6/9 Ted Dunning : I apologize for not reading your thread with great care, but I think that your problem is pretty clear. The issue is not to do with gets and puts overlapping. The issue is that a put or remove happened during the life of your iterator. One way to avoid this is to synchronize the entire method that does the deletion of old elements. To speed that up, you might just synchronize the scan for elements to delete and collect them into a list. Then you can delete them outside the loop. Since your scan is probably pretty fast, this may be sufficient. With very high levels of updates and threading, it would cause problems. Another option is to clone the table. I believe that some implementations of LRUMap in Lucene do copy-on-write semantics, but I don't think that collections has these. Without that, cloning will be as slow or slower than
Re: Using apache.commons.cli with Java 1.4.2
sebb-2-2 wrote: On 15/06/2009, esharris eshar...@mac.com wrote: esharris wrote: beeky wrote: I'm jumping in sort of late on this, but here goes. To locate local config issues do the following. Create a simple script, call it 'view_cpath.bat', to invoke your app and output the classpath before the line that calls your app. -- begin script (windows batch file example): echo classpath=%classpath% java my.org.myapp %* - end script invoke your app with view_cpath.bat ... normal arg list ... With classpath in hand, check the following: 1. is the cli jar file explicitly named in the classpath? *.jar will not work. 2. is the jar file actually in the place where the classpath says it should be? Use dir or ls on classpath entries to be sure. 3. check for misspellings of the jar file name in classpath. The spelling is relative, obviously both classpath entry and actual jar file must be spelled the same. Commons jar files have lots of '-' and '.', it is easy to get them wrong. I've done it many, many times! This will find the problem is it is just local configuration. To make sure you are using the correct jar file do the following. use 'jar tvf commons-cli-1.1.jar' (from the directory that contain the jar file) to view the contents of the jar file. In the output you should see something like: 423 Wed Jul 04 19:48:06 EDT 2007 org/apache/commons/cli/CommandLineParser.class If you don't see this you have a bad/wrong jar file. Try downloading again. Hope this helps, -=beeky esharris wrote: This the only message: Exception in thread main java.lang.NoClassDefFoundError: org/apache/commons/cli/CommandLineParser. I only have 1.4.2 java on my machine. Earl Emmanuel Bourg-3 wrote: esharris a écrit : IMHO, NoClassDefFoundError is hard to debug. Could you paste the full stack trace? Also, check that the code was compiled with -target 1.4 Emmanuel Bourg - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org Initially, there was no CLASSPATH. I added the long name of the commons-cli-1.2.jar to the class path. The execution of the bat file displayed the expected class path. But this didn't solve the problem. I also introduced a JAVA_HOME environment variable that has the path to the jdk. If I put both jars in the same directory, extract everything out of the jars, and do a java {path to main class}, it works. IMHO, my ability to set the class path to a jar is broken. And my ability to set the class path to something besides the current directory is broken. The java command ignores the classpath if you use the -jar option. This is by design, and is documented: http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/java.html#-jar See the last paragraph for the -jar option. The problems you are reporting don't seem to be specific to Commons CLI. -- View this message in context: http://www.nabble.com/Using-apache.commons.cli-with-Java-1.4.2-tp23962584p24042102.html Sent from the Commons - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org The problem is not specified to a particular jar. If I want to execute a class file with dependencies, I can do it using class directories or jar files that are not immediately in the current directory. I just use the -commandpath option and include the current directory. If I want to execute a Jar file with dependencies, I can't do it. I need to learn more about how to get Eclipse to create a manifest containing the right class pathes. -- View this message in context: http://www.nabble.com/Using-apache.commons.cli-with-Java-1.4.2-tp23962584p24054941.html Sent from the Commons - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [collections] LRUMap Problem ConcurrentModificationException
That's the one, René. Yeah, no real solution in that JIRA issue I'm afraid. :( But it shows you what's already been looked at. Otis -- Sematext -- http://sematext.com/ -- Lucene - Solr - Nutch - Original Message From: Renè Glanzer rene.glan...@gmail.com To: Commons Users List user@commons.apache.org Sent: Tuesday, June 16, 2009 6:05:26 AM Subject: Re: [collections] LRUMap Problem ConcurrentModificationException Hey Otis, i found this one: https://issues.apache.org/jira/browse/COLLECTIONS-3 but there is no solutions only an assumption at the end of the thread?? René 2009/6/15 Otis Gospodnetic : Btw. I think you'll find a report about this from a few years ago in the Collections JIRA. Just search for my name. Otis -- Sematext -- http://sematext.com/ -- Lucene - Solr - Nutch - Original Message From: Renè Glanzer To: Commons Users List Sent: Monday, June 15, 2009 12:00:54 PM Subject: Re: [collections] LRUMap Problem ConcurrentModificationException Yes of course, the code with the time based cache systems was set up with an ordniary HashMap. But when rapidly seach requests are generated the time based mechanism fails to delete old entries - cause they are not old enough - and so the cache will raise up until the entire VM memory is used. Then i found the LRUMap switched to it and bang Exception in my delete method. When i switch back to HashMap the code runs well - as currently on the productive system - except the open memory leak. René 2009/6/15 Leon Rosenberg : just out of curiosity have you tried the same code with a standard hashmap? Leon On Mon, Jun 15, 2009 at 4:37 PM, Renè Glanzerwrote: Hello, side note accepted :-) In my class I checked the get, put and remove methods. All are synchronized. As you can see also the code which wants to delete the elements is synchronized. So I've no clue where the ConcurrentModificationException is comming from :-( Thanks René 2009/6/15 Leon Rosenberg : Hello, on a side note, generics make reading of code easier :-) you haven't posted the whole code, but have you (double)checked that all other acesses to store are synchronized? regards Leon On Mon, Jun 15, 2009 at 2:31 PM, Renè Glanzerwrote: I'm calling the remove() method on the iterator. I know when i call the remove on the map itself it will cause the problem with my currently running iterator, but i'm aware of that. Here is the code block which should delete old entries: store: is the LRUMap birth: is a long which keeps the creation time when this is set to 0 the item should be deleted public void removeAllExpiredItems() { synchronized(this.store) { Iterator it=this.store.keySet().iterator(); while(it.hasNext()) { Object key=it.next(); Object o=this.get(key); if(o != null) { Item iEntry=(Item)this.store.get(key); if(iEntry.birth==0) it.remove(); //Here the exception occurs } } this.setLastCleanDate(new Date()); //only to know when the deleter run the last time } } Thanks for any help :-) René 2009/6/15 James Carman : Are you calling remove() on the iterator or on the map itself? On Mon, Jun 15, 2009 at 6:37 AM, Renè Glanzer wrote: Hello, is there still no help for me? Is somebody able to explain me, why i get this java.util.ConcurrentModificationException on iterating and calling remove() on the LRUMap? Please René 2009/6/10 Renè Glanzer : Hello Ted, thanks for the fast response. I understand that simultaneously puts and gets do not cause the exception cause they are synchronized in my class. And my stated code-fragment is the part which wants to delete the entries from the underlying LRUMap. And my code is wrapped in the synchronized block. But i think the LRUMap herselfe also iterates the entries and this maybe happens at the same time when my iterator is checking and trying to delete elements. My class is not implementing the LRUMap but has one LRUMap as a variable. So your solution to override the removeLRU(Entry) methode would not help meunfortunatelly :-( For now i really do not know how to solve the problem in an easy way without refractoring the entire code? Any other solutions? Thanks René 2009/6/9 Ted Dunning : I apologize for not reading your thread with great care, but I think that your problem is pretty clear. The issue is not to do with gets and puts overlapping. The issue is that a put or remove happened during the life of your iterator. One way to avoid this is to synchronize the entire method that does the deletion of old elements. To speed