Write to files asynchronously.
This commit is contained in:
parent
abc15e3a4c
commit
a63d98a2d7
@ -7,6 +7,7 @@ import java.io.IOException;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -30,8 +31,10 @@ public class RedisCommandHandler extends JedisPubSub
|
|||||||
|
|
||||||
private static final JsonParser _jsonParser = new JsonParser();
|
private static final JsonParser _jsonParser = new JsonParser();
|
||||||
|
|
||||||
private File _directory;
|
private final File _directory;
|
||||||
private Logger _logger;
|
private final Logger _logger;
|
||||||
|
|
||||||
|
private final ExecutorService _executorService = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
public RedisCommandHandler(File directory, Logger logger)
|
public RedisCommandHandler(File directory, Logger logger)
|
||||||
{
|
{
|
||||||
@ -93,14 +96,8 @@ public class RedisCommandHandler extends JedisPubSub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
writeFile(target, json);
|
||||||
Files.write(target.toPath(), Arrays.asList(json.split("\n")));
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (channel.equals(ReportServer.CHANNEL_DESTROY))
|
else if (channel.equals(ReportServer.CHANNEL_DESTROY))
|
||||||
{
|
{
|
||||||
@ -120,6 +117,11 @@ public class RedisCommandHandler extends JedisPubSub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void writeFile(File file, String json)
|
||||||
|
{
|
||||||
|
_executorService.submit(() -> Files.write(file.toPath(), Arrays.asList(json.split("\n"))));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPMessage(String s, String s1, String s2)
|
public void onPMessage(String s, String s1, String s2)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user