Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
2cf86718
G
glide
项目概览
沉迷打码的小凳子
/
glide
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glide
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
2cf86718
编写于
4月 26, 2015
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add options for handling uncaught exceptions.
Fixes #435.
上级
31640f60
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
69 addition
and
3 deletion
+69
-3
library/src/main/java/com/bumptech/glide/load/engine/executor/FifoPriorityThreadPoolExecutor.java
.../load/engine/executor/FifoPriorityThreadPoolExecutor.java
+69
-3
未找到文件。
library/src/main/java/com/bumptech/glide/load/engine/executor/FifoPriorityThreadPoolExecutor.java
浏览文件 @
2cf86718
package
com.bumptech.glide.load.engine.executor
;
import
android.util.Log
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.FutureTask
;
import
java.util.concurrent.PriorityBlockingQueue
;
import
java.util.concurrent.RunnableFuture
;
...
...
@@ -15,7 +19,38 @@ import java.util.concurrent.atomic.AtomicInteger;
* same time. Runnables with the same priority will be executed in FIFO order.
*/
public
class
FifoPriorityThreadPoolExecutor
extends
ThreadPoolExecutor
{
AtomicInteger
ordering
=
new
AtomicInteger
();
private
static
final
String
TAG
=
"PriorityExecutor"
;
private
final
AtomicInteger
ordering
=
new
AtomicInteger
();
private
final
UncaughtThrowableStrategy
uncaughtThrowableStrategy
;
/**
* A strategy for handling unexpected and uncaught throwables thrown by futures run on the pool.
*/
public
enum
UncaughtThrowableStrategy
{
/** Silently catches and ignores the uncaught throwables. */
IGNORE
,
/** Logs the uncaught throwables using {@link #TAG} and {@link Log}. */
LOG
{
@Override
protected
void
handle
(
Throwable
t
)
{
if
(
Log
.
isLoggable
(
TAG
,
Log
.
ERROR
))
{
Log
.
e
(
TAG
,
"Request threw uncaught throwable"
,
t
);
}
}
},
/** Rethrows the uncaught throwables to crash the app. */
THROW
{
@Override
protected
void
handle
(
Throwable
t
)
{
super
.
handle
(
t
);
throw
new
RuntimeException
(
t
);
}
};
protected
void
handle
(
Throwable
t
)
{
// Ignore.
}
}
/**
* Constructor to build a fixed thread pool with the given pool size using
...
...
@@ -24,12 +59,26 @@ public class FifoPriorityThreadPoolExecutor extends ThreadPoolExecutor {
* @param poolSize The number of threads.
*/
public
FifoPriorityThreadPoolExecutor
(
int
poolSize
)
{
this
(
poolSize
,
poolSize
,
0
,
TimeUnit
.
MILLISECONDS
,
new
DefaultThreadFactory
());
this
(
poolSize
,
UncaughtThrowableStrategy
.
LOG
);
}
/**
* Constructor to build a fixed thread pool with the given pool size using
* {@link com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor.DefaultThreadFactory}.
*
* @param poolSize The number of threads.
* @param uncaughtThrowableStrategy Dictates how the pool should handle uncaught and unexpected throwables
* thrown by Futures run by the pool.
*/
public
FifoPriorityThreadPoolExecutor
(
int
poolSize
,
UncaughtThrowableStrategy
uncaughtThrowableStrategy
)
{
this
(
poolSize
,
poolSize
,
0
,
TimeUnit
.
MILLISECONDS
,
new
DefaultThreadFactory
(),
uncaughtThrowableStrategy
);
}
public
FifoPriorityThreadPoolExecutor
(
int
corePoolSize
,
int
maximumPoolSize
,
long
keepAlive
,
TimeUnit
timeUnit
,
ThreadFactory
threadFactory
)
{
ThreadFactory
threadFactory
,
UncaughtThrowableStrategy
uncaughtThrowableStrategy
)
{
super
(
corePoolSize
,
maximumPoolSize
,
keepAlive
,
timeUnit
,
new
PriorityBlockingQueue
<
Runnable
>(),
threadFactory
);
this
.
uncaughtThrowableStrategy
=
uncaughtThrowableStrategy
;
}
@Override
...
...
@@ -37,6 +86,23 @@ public class FifoPriorityThreadPoolExecutor extends ThreadPoolExecutor {
return
new
LoadTask
<
T
>(
runnable
,
value
,
ordering
.
getAndIncrement
());
}
@Override
protected
void
afterExecute
(
Runnable
r
,
Throwable
t
)
{
super
.
afterExecute
(
r
,
t
);
if
(
t
==
null
&&
r
instanceof
Future
<?>)
{
Future
<?>
future
=
(
Future
<?>)
r
;
if
(
future
.
isDone
()
&&
!
future
.
isCancelled
())
{
try
{
future
.
get
();
}
catch
(
InterruptedException
e
)
{
uncaughtThrowableStrategy
.
handle
(
e
);
}
catch
(
ExecutionException
e
)
{
uncaughtThrowableStrategy
.
handle
(
e
);
}
}
}
}
/**
* A {@link java.util.concurrent.ThreadFactory} that builds threads with priority
* {@link android.os.Process#THREAD_PRIORITY_BACKGROUND}.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录