@@ -68,6 +68,7 @@ void submit(final LoadAndDisplayImageTask task) {
68
68
@ Override
69
69
public void run () {
70
70
boolean isImageCachedOnDisc = configuration .discCache .get (task .getLoadingUri ()).exists ();
71
+ initExecutorsIfNeed ();
71
72
if (isImageCachedOnDisc ) {
72
73
taskExecutorForCachedImages .execute (task );
73
74
} else {
@@ -79,9 +80,23 @@ public void run() {
79
80
80
81
/** Submits task to execution pool */
81
82
void submit (ProcessAndDisplayImageTask task ) {
83
+ initExecutorsIfNeed ();
82
84
taskExecutorForCachedImages .execute (task );
83
85
}
84
86
87
+ private void initExecutorsIfNeed () {
88
+ if (taskExecutor == null ) {
89
+ taskExecutor = createTaskExecutor ();
90
+ }
91
+ if (taskExecutorForCachedImages == null ) {
92
+ taskExecutorForCachedImages = createTaskExecutor ();
93
+ }
94
+ }
95
+
96
+ private Executor createTaskExecutor () {
97
+ return DefaultConfigurationFactory .createExecutor (configuration .threadPoolSize , configuration .threadPriority , configuration .tasksProcessingType );
98
+ }
99
+
85
100
/** Returns URI of image which is loading at this moment into passed {@link ImageView} */
86
101
String getLoadingUriForView (ImageView imageView ) {
87
102
return cacheKeysForImageViews .get (imageView .hashCode ());
@@ -145,24 +160,17 @@ void resume() {
145
160
}
146
161
}
147
162
148
- /** Stops all running display image tasks, discards all other scheduled tasks. Clears internal data. */
149
- void destroy () {
163
+ /** Stops engine, cancels all running and scheduled display image tasks. Clears internal data. */
164
+ void stop () {
150
165
if (!configuration .customExecutor ) {
151
- (( ExecutorService ) taskExecutor ). shutdownNow () ;
166
+ taskExecutor = null ;
152
167
}
153
168
if (!configuration .customExecutorForCachedImages ) {
154
- ((ExecutorService ) taskExecutorForCachedImages ).shutdownNow ();
155
- }
156
- if (taskDistributor != null ) {
157
- taskDistributor .shutdownNow ();
169
+ taskExecutorForCachedImages = null ;
158
170
}
159
171
160
172
cacheKeysForImageViews .clear ();
161
173
uriLocks .clear ();
162
-
163
- taskExecutor = null ;
164
- taskExecutorForCachedImages = null ;
165
- taskDistributor = null ;
166
174
}
167
175
168
176
ReentrantLock getLockForUri (String uri ) {
0 commit comments