Skip to content
Snippets Groups Projects
Commit 0adb00c2 authored by Jan-Mikael Ihanus's avatar Jan-Mikael Ihanus
Browse files

Threadlukkoa lisätty, ei vaikuta toiminnallisuuteen mitenkään.. ainakaan vielä

parent ce5a93a3
No related branches found
No related tags found
No related merge requests found
......@@ -10,10 +10,15 @@ import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public class DataStore {
public List<Asiakas> asiakkaat;
public List<Reitti> reitit;
ReadWriteLock lock = new ReentrantReadWriteLock();
private DataStore() {
asiakkaat = new ArrayList<>();
......@@ -42,6 +47,7 @@ public class DataStore {
}
public static DataStore load() {
try {
FileReader reader = new FileReader("data/data.json");
Gson gson = new Gson();
......@@ -53,13 +59,18 @@ public class DataStore {
return new DataStore();
}
}
public void save() {
lock.writeLock().lock(); //kirjoittaminen lukkoon
try (FileWriter writer = new FileWriter("data/data.json")) {
String jsonText = new GsonBuilder().setPrettyPrinting().create().toJson(this);
writer.write(jsonText);
} catch (IOException e) {
e.printStackTrace();
}
finally {
lock.writeLock().unlock(); //lukko auki
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment