Skip to content

Commit

Permalink
Create sub sessions in a seperate thread to prevent standalone hanging
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Apr 22, 2024
1 parent 3f17f98 commit 3c1ddc5
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,22 @@ public void init(SessionInfo sessionInfo, FriendSyncConfig friendSyncConfig) thr
subSessions = Arrays.asList(Constants.OBJECT_MAPPER.readValue(Paths.get(cache, "sub_sessions.json").toFile(), String[].class));
} catch (IOException ignored) { }

// Create the sub-session manager for each sub-session
for (String subSession : subSessions) {
try {
SubSessionManager subSessionManager = new SubSessionManager(subSession, this, Paths.get(cache, subSession).toString(), logger);
subSessionManager.init();
subSessionManager.friendManager().initAutoFriend(friendSyncConfig);
subSessionManagers.put(subSession, subSessionManager);
} catch (SessionCreationException | SessionUpdateException e) {
logger.error("Failed to create sub-session " + subSession, e);
// TODO Retry creation after 30s or so
// Create the sub-sessions in a new thread so we don't block the main thread
List<String> finalSubSessions = subSessions;
new Thread(() -> {
// Create the sub-session manager for each sub-session
for (String subSession : finalSubSessions) {
try {
SubSessionManager subSessionManager = new SubSessionManager(subSession, this, Paths.get(cache, subSession).toString(), logger);
subSessionManager.init();
subSessionManager.friendManager().initAutoFriend(friendSyncConfig);
subSessionManagers.put(subSession, subSessionManager);
} catch (SessionCreationException | SessionUpdateException e) {
logger.error("Failed to create sub-session " + subSession, e);
// TODO Retry creation after 30s or so
}
}
}
}).start();
}

@Override
Expand Down

0 comments on commit 3c1ddc5

Please sign in to comment.