}
private void load() throws IOException {
- JsonNode rootNode = jsonProcessor.readTree(Channels.newInputStream(fileChannel));
+ JsonNode rootNode;
+ synchronized (fileChannel) {
+ fileChannel.position(0);
+ rootNode = jsonProcessor.readTree(Channels.newInputStream(fileChannel));
+ }
JsonNode node = rootNode.get("deviceId");
if (node != null) {
.putPOJO("threadStore", threadStore)
;
try {
- fileChannel.position(0);
- jsonProcessor.writeValue(Channels.newOutputStream(fileChannel), rootNode);
- fileChannel.truncate(fileChannel.position());
- fileChannel.force(false);
+ synchronized (fileChannel) {
+ fileChannel.position(0);
+ jsonProcessor.writeValue(Channels.newOutputStream(fileChannel), rootNode);
+ fileChannel.truncate(fileChannel.position());
+ fileChannel.force(false);
+ }
} catch (Exception e) {
System.err.println(String.format("Error saving file: %s", e.getMessage()));
}