Skip to content

Commit 7c29fef

Browse files
committed
minor cleanup for copilot suggestions
1 parent 9c87d7b commit 7c29fef

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

analytics/src/main/java/com/segment/analytics/internal/AnalyticsClient.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public class AnalyticsClient {
4444
private static final Charset ENCODING = StandardCharsets.UTF_8;
4545
private Gson gsonInstance;
4646
private static final String instanceId = UUID.randomUUID().toString();
47+
private static final int WAIT_FOR_THREAD_COMPLETE_MS = 5000;
48+
private static final int TERMINATION_TIMEOUT_MS = 1000;
4749

4850
static {
4951
Map<String, String> library = new LinkedHashMap<>();
@@ -243,10 +245,10 @@ private void waitForLooperCompletion() {
243245
try {
244246
// Wait for the looper to complete processing the STOP message and finish
245247
// Use a reasonable timeout to avoid hanging indefinitely
246-
looperFuture.get(5, TimeUnit.SECONDS);
248+
looperFuture.get(WAIT_FOR_THREAD_COMPLETE_MS, TimeUnit.MILLISECONDS);
247249
log.print(VERBOSE, "Looper completed successfully.");
248250
} catch (Exception e) {
249-
log.print(ERROR, e, "Error waiting for looper to complete: %s", e.getMessage());
251+
log.print(ERROR, e, "Error waiting for looper to complete.");
250252
// Cancel the looper if it's taking too long or if there's an error
251253
if (!looperFuture.isDone()) {
252254
looperFuture.cancel(true);
@@ -260,14 +262,14 @@ public void shutdownAndWait(ExecutorService executor, String name) {
260262
boolean isLooperExecutor = name != null && name.equalsIgnoreCase("looper");
261263
try {
262264
executor.shutdown();
263-
boolean terminated = executor.awaitTermination(1, TimeUnit.SECONDS);
265+
boolean terminated = executor.awaitTermination(TERMINATION_TIMEOUT_MS, TimeUnit.MILLISECONDS);
264266
if (terminated) {
265267
log.print(VERBOSE, "%s executor terminated normally.", name);
266268
return;
267269
}
268-
if (isLooperExecutor) {
270+
if (isLooperExecutor) { // Handle looper - network could be passed in and should finish on its own
269271
// not terminated within timeout -> force shutdown
270-
log.print(VERBOSE, "%s did not terminate in %d ms; requesting shutdownNow().", name, 1);
272+
log.print(VERBOSE, "%s did not terminate in %d ms; requesting shutdownNow().", name, TERMINATION_TIMEOUT_MS);
271273
List<Runnable> dropped = executor.shutdownNow(); // interrupts running tasks
272274
log.print(
273275
VERBOSE,
@@ -276,7 +278,7 @@ public void shutdownAndWait(ExecutorService executor, String name) {
276278
dropped.size());
277279

278280
// optional short wait to give interrupted tasks a chance to exit
279-
boolean terminatedAfterForce = executor.awaitTermination(1, TimeUnit.SECONDS);
281+
boolean terminatedAfterForce = executor.awaitTermination(TERMINATION_TIMEOUT_MS, TimeUnit.MILLISECONDS);
280282
log.print(
281283
VERBOSE,
282284
"%s executor %s after shutdownNow().",

0 commit comments

Comments
 (0)