Skip to content

Commit ba69fe3

Browse files
committed
fix cache block
1 parent 6a2ca22 commit ba69fe3

File tree

2 files changed

+4
-32
lines changed

2 files changed

+4
-32
lines changed

src/main/java/Bootstrap.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -193,32 +193,6 @@ private static boolean isPortUsing(String host, int port) throws UnknownHostExce
193193
return true;
194194
}
195195

196-
//
197-
// /**
198-
// * config log4j2 setting
199-
// *
200-
// * @param logPath
201-
// * @throws IOException
202-
// * @throws FileNotFoundException
203-
// */
204-
// private static void createLog4j2Config(File log4jFile, String logPath) throws FileNotFoundException, IOException {
205-
//
206-
// if (log4jFile.exists()) {
207-
// return;
208-
// }
209-
//
210-
// String logTemplate = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<Configuration status=\"INFO\">\n" + " <properties>\n"
211-
// + " <property name=\"LOG_PATH\">{{LOG_PATH}}</property>\n" + " </properties>\n" + " <Appenders>\n"
212-
// + " <Console name=\"Console\" target=\"SYSTEM_OUT\">\n" + " <PatternLayout pattern=\"%c-%-4r %-5p [%d{yyyy-MM-dd HH:mm:ss}] %m%n\" />\n"
213-
// + " </Console>\n" + "\n" + " <RollingRandomAccessFile name=\"File\" fileName=\"${LOG_PATH}\"\n" + " filePattern=\"${LOG_PATH}-%d{yyyyMMdd}\">\n"
214-
// + " <PatternLayout pattern=\"%m%n\" />\n" + " <Policies>\n" + " <TimeBasedTriggeringPolicy interval=\"1\"\n"
215-
// + " modulate=\"true\" />\n" + " </Policies>\n" + " </RollingRandomAccessFile>\n" + "\n" + " </Appenders>\n" + "\n" + "\n"
216-
// + " <Loggers>\n" + " <Root level=\"info\">\n" + " <AppenderRef ref=\"Console\" />\n" + " <AppenderRef ref=\"File\" />\n"
217-
// + " </Root>\n" + " </Loggers>\n" + "</Configuration>";
218-
//
219-
// wirteFile(log4jFile.getAbsolutePath(), "utf-8", logTemplate.replace("{{LOG_PATH}}", logPath));
220-
//
221-
// }
222196

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

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

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

271-
// createLog4j2Config(new File(JcoderHome, "log4j2.xml"), logPath);
272241
}
273242

274243
/**

src/main/java/org/nlpcn/jcoder/run/mvc/cache/CacheEntry.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public class CacheEntry {
4343

4444
private LoadingCache<Args, Object> cache = null;
4545

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

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

76+
@Override
7477
public Object load(Args args) {
7578
return executeNoCache(args);
7679
}
7780

7881
@Override
7982
public ListenableFuture<Object> reload(final Args args, Object oldValue) {
80-
return ListenableFutureTask.create(() -> executeNoCache(args));
83+
return backgroundRefreshPools.submit(() -> executeNoCache(args));
8184
}
8285

8386
});

0 commit comments

Comments
 (0)