méthode synchronized à remplacer
Bonjour ,
voici mon problème j'utilise une méthode public synchronized pour accéder à un buffer , dans mon programme cette méthode est appelée de très nombreuses fois .
Ces appels à répétition provoquent une augmentation du nombre de thread et la saturation de la mémoire car le gargage collector n 'arrive plus à libérer de la mémoire trop d'appels dans la secodne
Comment je peux ré-écrire cette méthode pour éviter un verrou sur les threads et une libération plus rapide de la mémoire .
Merci de votre aide
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| private Buffer content = new Buffer();
public synchronized String getRow(final long lPosition) throws ApplicationPException {
String sRow = content.get(lPosition);
if (sRow == null) {
sRow = "";
long lLinePosition = 0;
if (lPosition != 1) {
if (lIndexLength != 0) {
lLinePosition = lIndexLength + 2 + (lPosition - 2)
* (lLineLength + 2);
} else {
lLinePosition = (lPosition - 1) * (lLineLength + 2);
}
}
try {
this.seek(lLinePosition);
sRow = readLine();
} catch (Exception eException) {
throw new ApplicationException(ApplicationException.ERREUR_ACCES_BASE,
"Erreur lors de la récupération du la ligne n°"
+ lLinePosition + " du fichier '" + this.sFilePath
+ "'");
}
if(!sFilePath.startsWith("APP")){
content.put(lPosition, sRow);
}
}
return sRow;
} |