From a28043bf2c04953ca942158c3cfe39753a39d8f2 Mon Sep 17 00:00:00 2001 From: Anil Koyuncu Date: Wed, 4 Apr 2018 21:51:15 +0200 Subject: [PATCH] pool --- .../violations/AkkaTreeLoader.java | 48 +++++++---------- .../FixPatternParser/violations/Compare.java | 54 ++++++++----------- 2 files changed, 40 insertions(+), 62 deletions(-) diff --git a/src/main/java/edu/lu/uni/serval/FixPatternParser/violations/AkkaTreeLoader.java b/src/main/java/edu/lu/uni/serval/FixPatternParser/violations/AkkaTreeLoader.java index 963730a..d37dfe3 100644 --- a/src/main/java/edu/lu/uni/serval/FixPatternParser/violations/AkkaTreeLoader.java +++ b/src/main/java/edu/lu/uni/serval/FixPatternParser/violations/AkkaTreeLoader.java @@ -354,39 +354,27 @@ public class AkkaTreeLoader { } public static ITree getSimpliedTree(String fn,JedisPoolConfig config) { JedisPool pool = new JedisPool(config, "127.0.0.1", Integer.valueOf(6399), 20000000); - HierarchicalActionSet actionSet = null; - try (Jedis inner = pool.getResource()) { + ITree tree = null; + Jedis inner = null; + try { + inner = pool.getResource(); String s = inner.get(fn.substring(1)); - actionSet = (HierarchicalActionSet) fromString(s); + HierarchicalActionSet actionSet = (HierarchicalActionSet) fromString(s); + + ITree parent = null; + ITree children =null; + tree = getASTTree(actionSet, parent, children); + tree.setParent(null); + } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); + }finally { + if (inner != null) { + inner.close(); + } } -// try { -// FileInputStream fi = new FileInputStream(new File(fn)); -// ObjectInputStream oi = new ObjectInputStream(fi); -// actionSet = (HierarchicalActionSet) oi.readObject(); -// oi.close(); -// fi.close(); -// -// -// } catch (FileNotFoundException e) { -// log.error("File not found"); -// e.printStackTrace(); -// } catch (IOException e) { -// log.error("Error initializing stream"); -// e.printStackTrace(); -// } catch (ClassNotFoundException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } - - ITree parent = null; - ITree children =null; - ITree tree = getASTTree(actionSet, parent, children); - tree.setParent(null); - return tree; } @@ -637,12 +625,12 @@ public class AkkaTreeLoader { poolConfig.setMaxTotal(128); poolConfig.setMaxIdle(128); poolConfig.setMinIdle(16); - poolConfig.setTestOnBorrow(true); - poolConfig.setTestOnReturn(true); + poolConfig.setTestOnBorrow(false); + poolConfig.setTestOnReturn(false); poolConfig.setTestWhileIdle(true); poolConfig.setMinEvictableIdleTimeMillis(Duration.ofMinutes(60).toMillis()); poolConfig.setTimeBetweenEvictionRunsMillis(Duration.ofHours(30).toMillis()); - poolConfig.setNumTestsPerEvictionRun(3); +// poolConfig.setNumTestsPerEvictionRun(3); poolConfig.setBlockWhenExhausted(true); return poolConfig; diff --git a/src/main/java/edu/lu/uni/serval/FixPatternParser/violations/Compare.java b/src/main/java/edu/lu/uni/serval/FixPatternParser/violations/Compare.java index 4c245fc..61beeba 100644 --- a/src/main/java/edu/lu/uni/serval/FixPatternParser/violations/Compare.java +++ b/src/main/java/edu/lu/uni/serval/FixPatternParser/violations/Compare.java @@ -31,33 +31,19 @@ public class Compare { public void coreCompare(String name , String inputPath, String innerPort) { JedisPool pool = new JedisPool(poolConfig, "127.0.0.1", Integer.valueOf(innerPort), 20000000); Map resultMap; - try (Jedis jedis = pool.getResource()) { - resultMap = jedis.hgetAll(name); - } - String[] split = name.split("_"); - - - String i = split[1]; - String j = split[2]; - String firstValue = resultMap.get("0"); - String secondValue = resultMap.get("1"); - -// String[] firstValueSplit = firstValue.split("GumTreeOutput2"); -// String[] secondValueSplit = secondValue.split("GumTreeOutput2"); -// -// if (firstValueSplit.length == 1) { -// firstValue = inputPath + firstValueSplit[0]; -// } else { -// firstValue = inputPath + firstValueSplit[1]; -// } -// -// if (secondValueSplit.length == 1) { -// secondValue = inputPath + secondValueSplit[0]; -// } else { -// secondValue = inputPath + secondValueSplit[1]; -// } + Jedis jedis = null; try { + jedis = pool.getResource(); + resultMap = jedis.hgetAll(name); + + String[] split = name.split("_"); + + + String i = split[1]; + String j = split[2]; + String firstValue = resultMap.get("0"); + String secondValue = resultMap.get("1"); ITree oldTree = getSimpliedTree(firstValue,poolConfig); @@ -87,22 +73,26 @@ public class Compare { || ((Double) jaccardSimilarity1).equals(1.0) || actions.size() == 0) { String matchKey = "match_" + (String.valueOf(i)) + "_" + String.valueOf(j); log.info(matchKey); - try (Jedis jedis = pool.getResource()) { - jedis.select(1); - jedis.set(matchKey, result); - } + + jedis.select(1); + jedis.set(matchKey, result); + } - try (Jedis jedis = pool.getResource()) { - jedis.del("pair_" + (String.valueOf(i)) + "_" + String.valueOf(j)); - } + + jedis.del("pair_" + (String.valueOf(i)) + "_" + String.valueOf(j)); + } catch (Exception e) { log.error(e.toString() + " {}", (name)); + }finally { + if (jedis != null) { + jedis.close(); + } } }