Java: Serialize object to file asynchronously
问题 I am making a Minecraft clone, and I have a Map<Vector3i, Chunk> called chunks that stores all the loaded chunks. Every frame, this loop runs: for(Vector3i v:chunksToUnrender){ ... CompletableFuture.runAsync(() -> { try { chunks.get(v).toFile(new File(String.format("res-server/regions/%s.%s.%s.mcr", v.x, v.y, v.z))); synchronized (chunksStateGuard) { chunks.remove(v); } } catch(IOException e) { e.printStackTrace(); System.err.println("Unable to save chunk " + Utils.format3i(v)); } }); } The