Skip to content

Commit

Permalink
fix cache block
Browse files Browse the repository at this point in the history
  • Loading branch information
ansjsun committed Jul 12, 2018
1 parent 6a2ca22 commit ba69fe3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 32 deletions.
31 changes: 0 additions & 31 deletions src/main/java/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,32 +193,6 @@ private static boolean isPortUsing(String host, int port) throws UnknownHostExce
return true;
}

//
// /**
// * config log4j2 setting
// *
// * @param logPath
// * @throws IOException
// * @throws FileNotFoundException
// */
// private static void createLog4j2Config(File log4jFile, String logPath) throws FileNotFoundException, IOException {
//
// if (log4jFile.exists()) {
// return;
// }
//
// String logTemplate = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<Configuration status=\"INFO\">\n" + " <properties>\n"
// + " <property name=\"LOG_PATH\">{{LOG_PATH}}</property>\n" + " </properties>\n" + " <Appenders>\n"
// + " <Console name=\"Console\" target=\"SYSTEM_OUT\">\n" + " <PatternLayout pattern=\"%c-%-4r %-5p [%d{yyyy-MM-dd HH:mm:ss}] %m%n\" />\n"
// + " </Console>\n" + "\n" + " <RollingRandomAccessFile name=\"File\" fileName=\"${LOG_PATH}\"\n" + " filePattern=\"${LOG_PATH}-%d{yyyyMMdd}\">\n"
// + " <PatternLayout pattern=\"%m%n\" />\n" + " <Policies>\n" + " <TimeBasedTriggeringPolicy interval=\"1\"\n"
// + " modulate=\"true\" />\n" + " </Policies>\n" + " </RollingRandomAccessFile>\n" + "\n" + " </Appenders>\n" + "\n" + "\n"
// + " <Loggers>\n" + " <Root level=\"info\">\n" + " <AppenderRef ref=\"Console\" />\n" + " <AppenderRef ref=\"File\" />\n"
// + " </Root>\n" + " </Loggers>\n" + "</Configuration>";
//
// wirteFile(log4jFile.getAbsolutePath(), "utf-8", logTemplate.replace("{{LOG_PATH}}", logPath));
//
// }

private static void parseFile(String file) throws UnsupportedEncodingException, FileNotFoundException, IOException {
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"))) {
Expand Down Expand Up @@ -253,10 +227,6 @@ private static void parseFile(String file) throws UnsupportedEncodingException,
}

private static void makeFiles(File JcoderHome, String logPath) throws FileNotFoundException, IOException {
File tmpDir = new File(JcoderHome, "tmp"); // create tmp dir
if (!tmpDir.exists()) {
tmpDir.mkdirs();
}

File pluginDir = new File(JcoderHome, "web"); // create web dir
if (!pluginDir.exists()) {
Expand All @@ -268,7 +238,6 @@ private static void makeFiles(File JcoderHome, String logPath) throws FileNotFou
groupDir.mkdirs();
}

// createLog4j2Config(new File(JcoderHome, "log4j2.xml"), logPath);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/nlpcn/jcoder/run/mvc/cache/CacheEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class CacheEntry {

private LoadingCache<Args, Object> cache = null;

private ListeningExecutorService backgroundRefreshPools =
MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(20));
public CacheEntry(Task task, Method method, int time, int size, boolean block) {
this.task = task;

Expand Down Expand Up @@ -71,13 +73,14 @@ public Object load(Args args) {
} else {
cache = CacheBuilder.newBuilder().maximumSize(this.size).refreshAfterWrite(time, TimeUnit.SECONDS).build(new CacheLoader<Args, Object>() {

@Override
public Object load(Args args) {
return executeNoCache(args);
}

@Override
public ListenableFuture<Object> reload(final Args args, Object oldValue) {
return ListenableFutureTask.create(() -> executeNoCache(args));
return backgroundRefreshPools.submit(() -> executeNoCache(args));
}

});
Expand Down

0 comments on commit ba69fe3

Please sign in to comment.