Thanks to all. The problem was the static hashmap. I removed the static key=
word to the variable and problem solved.
----- Mensaje original -----
De: "Christopher Schultz" <chris@christopherschultz.net>
Para: "Tomcat Users List" <users@tomcat.apache.org>
Enviados: Lunes, 1 de Agosto 2011 20:11:27
Asunto: Re: Problem with threads in stage Service (Tomcat 7.0.14)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Alejandro,
On 7/29/2011 11:55 AM, Alejandro Henao Gonz=C3=A1lez wrote:
> public class HTMLEncoder { private static Map mapChar2HTMLEntity;
>
> private final static char [] characters =3D {
> '=C3=A1','=C3=BA','=C3=B3','=C3=A9','=C3=AD','=C3=B1','=C3=81','=C3=9A','=
=C3=93','=C3=89','=C3=8D','=C2=B0','=C3=BC' }; private final
> static String[] entities =3D {
> "á","ú","ó","é","í","ñ","&Aacut=
e;","Ú","Ó","É","Í","°","ü"
> };
>
> public HTMLEncoder() { mapChar2HTMLEntity=3D new HashMap(); int
> longueur =3D characters.length;
>
> for (int i =3D 0; i < longueur; i++) mapChar2HTMLEntity.put(new
> Character(characters[i]), entities[i]); }
So you have Character -> String (entity reference). Your Map is not
synchronized, but it doesn't have to be: you are only calling get() on
it so there shouldn't be any synchronization issues here.
> public String encode(String s) { int longueur =3D s.length(); final
> StringBuffer sb =3D new StringBuffer(longueur * 2);
Big buffer every time?
> char ch;
>
> for (int i =3D0; i < longueur ; ++i) { ch =3D s.charAt(i);
>
> if ((ch >=3D 63 && ch <=3D 90) || (ch >=3D 97 && ch <=3D
122)) sb.append(=
ch);
> else { String ss =3D (String)mapChar2HTMLEntity.get(new
> Character(ch));
New Character object every time? Mmm. You might want to choose a more
optimized storage system so you don't have to create a new object every
time.
> if(ss=3D=3Dnull) sb.append(ch); else sb.append(ss); } } return
> sb.toString(); }
Aside from any other strange issues you are having, you might be wasting
a lot of time (and invoking a lot of GC) by creating a large
StringBuffer for every invocation. You might want some more complicated
logic to determine if you even need to create such a buffer.
Honestly, I don't see much wrong with this class. I don't see any use of
System.gc and I don't see any connection reset. Was there a post that I
missed?
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk43Tr4ACgkQ9CaO5/Lv0PBk4QCglB4MNYVbEvwsqZFwiOYupAUv
J84AnRAnw2o6PwTRiaNnNFc9iyNq0pUS
=3DUWQu
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
|