This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.4.0; add base activity class for convenience;
- Loading branch information
Jerry Chen
committed
Aug 3, 2019
1 parent
c291e3a
commit 080a8c3
Showing
6 changed files
with
50 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/src/main/java/jerryc05/unlockme/activities/MyActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package jerryc05.unlockme.activities; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import java.util.concurrent.LinkedBlockingQueue; | ||
import java.util.concurrent.RejectedExecutionHandler; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import jerryc05.unlockme.helpers.UserInterface; | ||
|
||
abstract class MyActivity extends Activity { | ||
|
||
private static final String TAG = "MyActivity"; | ||
static ThreadPoolExecutor threadPoolExecutor; | ||
|
||
static ThreadPoolExecutor getThreadPoolExecutor( | ||
@NonNull final Context context) { | ||
if (threadPoolExecutor == null) { | ||
RejectedExecutionHandler rejectedExecutionHandler | ||
= new RejectedExecutionHandler() { | ||
@Override | ||
public void rejectedExecution(Runnable runnable, | ||
ThreadPoolExecutor threadPoolExecutor) { | ||
UserInterface.showExceptionToNotificationNoRethrow( | ||
"ThreadPoolExecutor:\n>>> " | ||
+ threadPoolExecutor.toString() | ||
+ "\non " + TAG + " rejected:\n >>> " | ||
+ runnable.toString(), | ||
"threadPoolExecutor#rejectedExecution()", | ||
context); | ||
} | ||
}; | ||
final int processorCount = Runtime.getRuntime().availableProcessors(); | ||
threadPoolExecutor = new ThreadPoolExecutor(processorCount, | ||
2 * processorCount, 5, TimeUnit.SECONDS, | ||
new LinkedBlockingQueue<>(1), rejectedExecutionHandler); | ||
threadPoolExecutor.allowCoreThreadTimeOut(true); | ||
} | ||
return threadPoolExecutor; | ||
} | ||
} |
File renamed without changes
File renamed without changes
File renamed without changes