From 20b9271b8c93e9911ba49851d0bf6099eef1d97d Mon Sep 17 00:00:00 2001 From: PatrikBuhr Date: Mon, 3 Jun 2019 06:59:50 +0000 Subject: DFC, Purging the cache of published files occasionally fails Solved a threading issue. Change-Id: I1272cadd5d8bc8bb8ffc4c3d33c9b5c706470864 Issue-ID: DCAEGEN2-1588 Signed-off-by: PatrikBuhr --- .../collectors/datafile/service/PublishedFileCache.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCache.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCache.java index ff267815..475e0224 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCache.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCache.java @@ -28,7 +28,7 @@ import java.util.Map; * the key was last used. */ public class PublishedFileCache { - private final Map publishedFiles = Collections.synchronizedMap(new HashMap()); + private final Map publishedFiles = new HashMap(); /** * Adds a file to the cache. @@ -36,7 +36,7 @@ public class PublishedFileCache { * @param path the name of the file to add. * @return null if the file is not already in the cache. */ - public Instant put(Path path) { + public synchronized Instant put(Path path) { return publishedFiles.put(path, Instant.now()); } @@ -45,7 +45,7 @@ public class PublishedFileCache { * * @param localFileName name of the file to remove. */ - public void remove(Path localFileName) { + public synchronized void remove(Path localFileName) { publishedFiles.remove(localFileName); } @@ -54,7 +54,7 @@ public class PublishedFileCache { * * @param now the instant will determine which files that will be purged. */ - public void purge(Instant now) { + public synchronized void purge(Instant now) { for (Iterator> it = publishedFiles.entrySet().iterator(); it.hasNext();) { Map.Entry pair = it.next(); if (isCachedPublishedFileOutdated(now, pair.getValue())) { @@ -63,7 +63,7 @@ public class PublishedFileCache { } } - public int size() { + public synchronized int size() { return publishedFiles.size(); } -- cgit 1.2.3-korg