Skip to content

Commit fefa604

Browse files
committed
improve
1 parent 514bc23 commit fefa604

3 files changed

Lines changed: 16 additions & 23 deletions

File tree

sentry-android-core/src/main/java/io/sentry/android/core/DefaultAndroidEventProcessor.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,7 @@
44
import android.content.pm.PackageInfo;
55
import android.content.pm.PackageManager;
66
import android.os.Build;
7-
import io.sentry.DateUtils;
8-
import io.sentry.EventProcessor;
9-
import io.sentry.Hint;
10-
import io.sentry.IpAddressUtils;
11-
import io.sentry.NoOpLogger;
12-
import io.sentry.SentryAttributeType;
13-
import io.sentry.SentryBaseEvent;
14-
import io.sentry.SentryEvent;
15-
import io.sentry.SentryLevel;
16-
import io.sentry.SentryLogEvent;
17-
import io.sentry.SentryLogEventAttributeValue;
18-
import io.sentry.SentryReplayEvent;
7+
import io.sentry.*;
198
import io.sentry.android.core.internal.util.AndroidThreadChecker;
209
import io.sentry.android.core.performance.AppStartMetrics;
2110
import io.sentry.android.core.performance.TimeSpan;
@@ -66,15 +55,16 @@ public DefaultAndroidEventProcessor(
6655
// don't ref. to method reference, theres a bug on it
6756
// noinspection Convert2MethodRef
6857
// some device info performs disk I/O, but it's result is cached, let's pre-cache it
58+
@Nullable Future<DeviceInfoUtil> deviceInfoUtil;
6959
final @NotNull ExecutorService executorService = Executors.newSingleThreadExecutor();
7060
try {
71-
this.deviceInfoUtil =
61+
deviceInfoUtil =
7262
executorService.submit(() -> DeviceInfoUtil.getInstance(this.context, options));
7363
} catch (RejectedExecutionException e) {
74-
options
75-
.getLogger()
76-
.log(SentryLevel.WARNING, "Device info caching task rejected.", e);
64+
deviceInfoUtil = null;
65+
options.getLogger().log(SentryLevel.WARNING, "Device info caching task rejected.", e);
7766
}
67+
this.deviceInfoUtil = deviceInfoUtil;
7868
executorService.shutdown();
7969
}
8070

sentry/src/main/java/io/sentry/Scopes.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import io.sentry.util.SpanUtils;
1313
import io.sentry.util.TracingUtils;
1414
import java.io.Closeable;
15-
import java.util.ArrayList;
16-
import java.util.Collections;
1715
import java.util.List;
1816
import java.util.concurrent.RejectedExecutionException;
1917
import org.jetbrains.annotations.ApiStatus;

sentry/src/main/java/io/sentry/SentryExecutorService.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public SentryExecutorService() {
5454
}
5555

5656
@Override
57-
public @NotNull Future<?> submit(final @NotNull Runnable runnable) throws RejectedExecutionException {
57+
public @NotNull Future<?> submit(final @NotNull Runnable runnable)
58+
throws RejectedExecutionException {
5859
if (executorService.getQueue().size() < MAX_QUEUE_SIZE) {
5960
return executorService.submit(runnable);
6061
}
@@ -67,7 +68,8 @@ public SentryExecutorService() {
6768
}
6869

6970
@Override
70-
public @NotNull <T> Future<T> submit(final @NotNull Callable<T> callable) throws RejectedExecutionException {
71+
public @NotNull <T> Future<T> submit(final @NotNull Callable<T> callable)
72+
throws RejectedExecutionException {
7173
if (executorService.getQueue().size() < MAX_QUEUE_SIZE) {
7274
return executorService.submit(callable);
7375
}
@@ -80,7 +82,8 @@ public SentryExecutorService() {
8082
}
8183

8284
@Override
83-
public @NotNull Future<?> schedule(final @NotNull Runnable runnable, final long delayMillis) throws RejectedExecutionException {
85+
public @NotNull Future<?> schedule(final @NotNull Runnable runnable, final long delayMillis)
86+
throws RejectedExecutionException {
8487
if (executorService.getQueue().size() < MAX_QUEUE_SIZE) {
8588
return executorService.schedule(runnable, delayMillis, TimeUnit.MILLISECONDS);
8689
}
@@ -124,10 +127,12 @@ public void prewarm() {
124127
executorService.submit(
125128
() -> {
126129
try {
127-
// schedule a bunch of dummy runnables in the future that will never execute to trigger
130+
// schedule a bunch of dummy runnables in the future that will never execute to
131+
// trigger
128132
// queue growth and then purge the queue
129133
for (int i = 0; i < INITIAL_QUEUE_SIZE; i++) {
130-
final Future<?> future = executorService.schedule(dummyRunnable, 365L, TimeUnit.DAYS);
134+
final Future<?> future =
135+
executorService.schedule(dummyRunnable, 365L, TimeUnit.DAYS);
131136
future.cancel(true);
132137
}
133138
executorService.purge();

0 commit comments

Comments
 (0)