better concurrency in ViewImage icon cache and OOM protection for too large icon caches

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7621 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent b1a8d0c020
commit 01b968d836

@ -28,14 +28,16 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.storage.ConcurrentARC;
import net.yacy.document.ImageParser;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.util.MemoryControl;
import de.anomic.crawler.CrawlProfile;
import de.anomic.search.Switchboard;
@ -44,7 +46,7 @@ import de.anomic.server.serverSwitch;
public class ViewImage {
private static HashMap<String, Image> iconcache = new HashMap<String, Image>();
private static Map<String, Image> iconcache = new ConcurrentARC<String, Image>(1000, Math.max(10, Math.min(32, Runtime.getRuntime().availableProcessors() * 2)));
private static String defaulticon = "htroot/env/grafics/dfltfvcn.ico";
private static byte[] defaulticonb;
static {
@ -86,6 +88,7 @@ public class ViewImage {
int maxheight = post.getInt("maxheight", 0);
// get the image as stream
if (MemoryControl.shortStatus()) iconcache.clear();
Image scaled = iconcache.get(urlString);
if (scaled == null) {
byte[] resourceb = null;

Loading…
Cancel
Save