mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-22 14:11:00 +00:00
Retry create worker thread
This commit is contained in:
parent
b64966a9f7
commit
a13772d856
1 changed files with 17 additions and 4 deletions
|
@ -297,10 +297,23 @@ public class Helper {
|
|||
|
||||
@Override
|
||||
public Thread newThread(@NonNull Runnable runnable) {
|
||||
Thread thread = new Thread(runnable);
|
||||
thread.setName("FairEmail_bg_" + name + "_" + threadId.getAndIncrement());
|
||||
thread.setPriority(THREAD_PRIORITY_BACKGROUND);
|
||||
return thread;
|
||||
int delay = 1;
|
||||
while (true)
|
||||
try {
|
||||
Thread thread = new Thread(runnable);
|
||||
thread.setName("FairEmail_bg_" + name + "_" + threadId.getAndIncrement());
|
||||
thread.setPriority(THREAD_PRIORITY_BACKGROUND);
|
||||
return thread;
|
||||
} catch (OutOfMemoryError ex) {
|
||||
Log.w(ex);
|
||||
try {
|
||||
Thread.sleep(delay * 1000L);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
delay *= 2;
|
||||
if (delay > 7)
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue