Skip to content

Commit f4f04ba

Browse files
authored
Merge pull request #506 from Countly/executor-flag
Executor changes
2 parents ab332d2 + 0dc3da9 commit f4f04ba

5 files changed

Lines changed: 40 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## X.X.X
2+
* Added a new config flag `setUseSerialExecutor(boolean useSerial)` for selecting immediate request executor type.
3+
* Immediate requests now will be run by parallel executor instead of serial by default.
4+
15
## 25.4.4
26
* Improved disk size calculation in crash reports.
37

sdk/src/main/java/ly/count/android/sdk/Countly.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ private static class SingletonHolder {
202202

203203
protected CountlyConfig config_ = null;
204204

205+
// for executor choice of immediate requests
206+
boolean useSerialExecutorInternal = false;
207+
205208
//fields for tracking push token debounce
206209
final static long lastRegistrationCallDebounceDuration = 60 * 1000;//60seconds
207210
long lastRegistrationCallTs = 0;
@@ -369,6 +372,9 @@ public synchronized Countly init(CountlyConfig config) {
369372
config.sdkInternalLimits.maxKeyLength = maxKeyLengthDefault;
370373
}
371374

375+
// should be here for sbs and hc
376+
useSerialExecutorInternal = config.useSerialExecutor;
377+
372378
if (config.sdkInternalLimits.maxValueSize != null) {
373379
if (config.sdkInternalLimits.maxValueSize < 1) {
374380
config.sdkInternalLimits.maxValueSize = 1;

sdk/src/main/java/ly/count/android/sdk/CountlyConfig.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ public class CountlyConfig {
206206
boolean sdkBehaviorSettingsRequestsDisabled = false;
207207
int requestTimeoutDuration = 30; // in seconds
208208

209+
// If set to true, immediate requests will use serial AsyncTask executor instead of the thread pool
210+
boolean useSerialExecutor = false;
211+
209212
/**
210213
* THIS VARIABLE SHOULD NOT BE USED
211214
* IT IS ONLY FOR INTERNAL TESTING
@@ -1052,6 +1055,19 @@ public synchronized CountlyConfig setRequestTimeoutDuration(int requestTimeoutDu
10521055
return this;
10531056
}
10541057

1058+
/**
1059+
* To select the legacy AsyncTask.execute (serial executor) or
1060+
* instead executeOnExecutor(THREAD_POOL_EXECUTOR)
1061+
* Default is false and the SDK will use the thread pool executor.
1062+
*
1063+
* @param useSerial set to true to use serial executor
1064+
* @return Returns the same config object for convenient linking
1065+
*/
1066+
public synchronized CountlyConfig setUseSerialExecutor(boolean useSerial) {
1067+
this.useSerialExecutor = useSerial;
1068+
return this;
1069+
}
1070+
10551071
/**
10561072
* APM configuration interface to be used with CountlyConfig
10571073
*/

sdk/src/main/java/ly/count/android/sdk/ImmediateRequestMaker.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@ public void doWork(@NonNull String requestData, @Nullable String customEndpoint,
3131
assert cp != null;
3232
assert log != null;
3333
assert callback != null;
34-
35-
this.execute(requestData, customEndpoint, cp, requestShouldBeDelayed, networkingIsEnabled, callback, log);
34+
if (Countly.sharedInstance().useSerialExecutorInternal) {
35+
log.d("[ImmediateRequestMaker] Using serial executor");
36+
this.execute(requestData, customEndpoint, cp, requestShouldBeDelayed, networkingIsEnabled, callback, log);
37+
} else {
38+
log.d("[ImmediateRequestMaker] Using parallel executor");
39+
this.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, requestData, customEndpoint, cp, requestShouldBeDelayed, networkingIsEnabled, callback, log);
40+
}
3641
}
3742

3843
/**

sdk/src/main/java/ly/count/android/sdk/PreflightRequestMaker.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ public void doWork(@NonNull String requestData, @Nullable String customEndpoint,
1818
assert cp != null;
1919
assert log != null;
2020
assert callback != null;
21-
22-
this.execute(requestData, customEndpoint, cp, requestShouldBeDelayed, networkingIsEnabled, callback, log);
21+
if (Countly.sharedInstance().useSerialExecutorInternal) {
22+
log.d("[PreflightRequestMaker] Using serial executor");
23+
this.execute(requestData, customEndpoint, cp, requestShouldBeDelayed, networkingIsEnabled, callback, log);
24+
} else {
25+
log.d("[PreflightRequestMaker] Using parallel executor");
26+
this.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, requestData, customEndpoint, cp, requestShouldBeDelayed, networkingIsEnabled, callback, log);
27+
}
2328
}
2429

2530
/**

0 commit comments

Comments
 (0)