james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Norman Maurer ...@byteaction.de>
Subject Re: svn commit: r424769 - /james/server/trunk/src/java/org/apache/james/util/RoaminUsersHelper.java
Date Sun, 23 Jul 2006 17:29:12 GMT
Thx for the tip.. Stefano allready tells me that this will maybe the
better way.. let us see.

thx
Norman

Am Sonntag, den 23.07.2006, 19:30 +0200 schrieb Zsombor:
> Instead of this, you should modify the code to: 
> 
>  public static void removeExpiredIP(long clearTime) {
>    synchronized(ipMap) {
>         Iterator storedIP = ipMap.keySet().iterator();
>         long currTime = System.currentTimeMillis();
> 
>         while (storedIP.hasNext()) {
>             String key = storedIP.next().toString();
>             long storedTime = Long.parseLong((String) ipMap.get(key));
> 
>             // remove the ip from the map when it is expired
>             if ((currTime - clearTime) > storedTime) {
>                ipMap.remove(key);
>             }
>         }
>    }
>  }
> 
> Or something like that.
> 
> BR,
>  Zsombor
> 
> 
> 2006. 07. 23, vasárnap keltezéssel 17.15-kor norman@apache.org ezt írta:
> > Author: norman
> > Date: Sun Jul 23 10:15:56 2006
> > New Revision: 424769
> > 
> > URL: http://svn.apache.org/viewvc?rev=424769&view=rev
> > Log:
> > Catch ConcurrentModificationException if its thrown
> > 
> > Modified:
> >     james/server/trunk/src/java/org/apache/james/util/RoaminUsersHelper.java
> > 
> > Modified: james/server/trunk/src/java/org/apache/james/util/RoaminUsersHelper.java
> > URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/util/RoaminUsersHelper.java?rev=424769&r1=424768&r2=424769&view=diff
> > ==============================================================================
> > --- james/server/trunk/src/java/org/apache/james/util/RoaminUsersHelper.java (original)
> > +++ james/server/trunk/src/java/org/apache/james/util/RoaminUsersHelper.java Sun
Jul 23 10:15:56 2006
> > @@ -17,6 +17,7 @@
> >  package org.apache.james.util;
> >  
> >  import java.util.Collections;
> > +import java.util.ConcurrentModificationException;
> >  import java.util.HashMap;
> >  import java.util.Iterator;
> >  import java.util.Map;
> > @@ -33,7 +34,7 @@
> >      /**
> >       * The map in which the ipAddresses and timestamp stored
> >       */
> > -    public static Map ipMap =  Collections.synchronizedMap(new HashMap());
> > +    public static Map ipMap = Collections.synchronizedMap(new HashMap());
> >  
> >      /**
> >       * Default expire time in ms (1 hour)
> > @@ -58,7 +59,10 @@
> >       *            The ipAddress
> >       */
> >      public static void addIPAddress(String ipAddress) {
> > -        ipMap.put(ipAddress, Long.toString(System.currentTimeMillis()));
> > +        try {
> > +            ipMap.put(ipAddress, Long.toString(System.currentTimeMillis()));
> > +        } catch (ConcurrentModificationException e) {
> > +        }
> >      }
> >  
> >      /**
> > @@ -86,7 +90,10 @@
> >  
> >              // remove the ip from the map when it is expired
> >              if ((currTime - clearTime) > storedTime) {
> > -                ipMap.remove(key);
> > +                try {
> > +                    ipMap.remove(key);
> > +                } catch (ConcurrentModificationException e) {
> > +                }
> >              }
> >          }
> >      }
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> > For additional commands, e-mail: server-dev-help@james.apache.org
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
> 
> !EXCUBATOR:1,44c3b17a43381533910195!

Mime
View raw message