mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-10-31 07:50:09 +01:00
Fixed possible ExecutorService leak in BukkitImporter
This commit is contained in:
parent
4f68a59dcb
commit
9616d5b6f0
@ -89,17 +89,12 @@ public abstract class BukkitImporter implements Importer {
|
|||||||
public final void processImport() {
|
public final void processImport() {
|
||||||
ExecutorService service = Executors.newCachedThreadPool();
|
ExecutorService service = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
submitTo(service, this::processServerData);
|
|
||||||
submitTo(service, this::processUserData);
|
|
||||||
|
|
||||||
service.shutdown();
|
|
||||||
try {
|
try {
|
||||||
service.awaitTermination(20, TimeUnit.MINUTES);
|
submitTo(service, this::processServerData);
|
||||||
} catch (InterruptedException e) {
|
submitTo(service, this::processUserData);
|
||||||
service.shutdownNow();
|
} finally {
|
||||||
Thread.currentThread().interrupt();
|
shutdownService(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processServerData() {
|
private void processServerData() {
|
||||||
@ -111,16 +106,12 @@ public abstract class BukkitImporter implements Importer {
|
|||||||
|
|
||||||
ExecutorService service = Executors.newCachedThreadPool();
|
ExecutorService service = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
SaveOperations save = dbSystem.getDatabase().save();
|
|
||||||
submitTo(service, () -> save.insertTPS(ImmutableMap.of(serverUUID.get(), serverImportData.getTpsData())));
|
|
||||||
submitTo(service, () -> save.insertCommandUsage(ImmutableMap.of(serverUUID.get(), serverImportData.getCommandUsages())));
|
|
||||||
|
|
||||||
service.shutdown();
|
|
||||||
try {
|
try {
|
||||||
service.awaitTermination(20, TimeUnit.MINUTES);
|
SaveOperations save = dbSystem.getDatabase().save();
|
||||||
} catch (InterruptedException e) {
|
submitTo(service, () -> save.insertTPS(ImmutableMap.of(serverUUID.get(), serverImportData.getTpsData())));
|
||||||
service.shutdownNow();
|
submitTo(service, () -> save.insertCommandUsage(ImmutableMap.of(serverUUID.get(), serverImportData.getCommandUsages())));
|
||||||
Thread.currentThread().interrupt();
|
} finally {
|
||||||
|
shutdownService(service);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,19 +156,27 @@ public abstract class BukkitImporter implements Importer {
|
|||||||
|
|
||||||
ExecutorService service = Executors.newCachedThreadPool();
|
ExecutorService service = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
SaveOperations save = dbSystem.getDatabase().save();
|
try {
|
||||||
|
SaveOperations save = dbSystem.getDatabase().save();
|
||||||
|
|
||||||
// TODO Replace with a transaction
|
// TODO Replace with a transaction
|
||||||
save.insertUsers(users);
|
save.insertUsers(users);
|
||||||
submitTo(service, () -> save.insertSessions(ImmutableMap.of(serverUUID.get(), sessions), true));
|
submitTo(service, () -> save.insertSessions(ImmutableMap.of(serverUUID.get(), sessions), true));
|
||||||
submitTo(service, () -> save.kickAmount(timesKicked));
|
submitTo(service, () -> save.kickAmount(timesKicked));
|
||||||
submitTo(service, () -> save.insertUserInfo(ImmutableMap.of(serverUUID.get(), userInfo)));
|
submitTo(service, () -> save.insertUserInfo(ImmutableMap.of(serverUUID.get(), userInfo)));
|
||||||
submitTo(service, () -> save.insertNicknames(ImmutableMap.of(serverUUID.get(), nickNames)));
|
submitTo(service, () -> save.insertNicknames(ImmutableMap.of(serverUUID.get(), nickNames)));
|
||||||
submitTo(service, () -> save.insertAllGeoInfo(geoInfo));
|
submitTo(service, () -> save.insertAllGeoInfo(geoInfo));
|
||||||
|
} finally {
|
||||||
|
shutdownService(service);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void shutdownService(ExecutorService service) {
|
||||||
service.shutdown();
|
service.shutdown();
|
||||||
try {
|
try {
|
||||||
service.awaitTermination(20, TimeUnit.MINUTES);
|
if (!service.awaitTermination(20, TimeUnit.MINUTES)) {
|
||||||
|
service.shutdownNow();
|
||||||
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
service.shutdownNow();
|
service.shutdownNow();
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
|
Loading…
Reference in New Issue
Block a user