]>
iEval git - fonbot.git/blob - fonbot/ExecutableRunnable.java
1 package ro
.ieval
.fonbot
;
3 import java
.util
.LinkedList
;
4 import java
.util
.Queue
;
5 import java
.util
.concurrent
.Executor
;
6 import java
.util
.concurrent
.Executors
;
9 * Copyright © 2013 Marius Gavrilescu
11 * This file is part of FonBot.
13 * FonBot is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
18 * FonBot is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with FonBot. If not, see <http://www.gnu.org/licenses/>.
28 * Slim alternative to AsyncTask.<p>
30 * Differences from AsyncTask:
32 * <li>No onPreExecute or onPostExecute
33 * <li>No progress support
34 * <li>Can be retried if necessary
37 * @author Marius Gavrilescu <marius@ieval.ro>
39 abstract class ExecutableRunnable
implements Runnable
{
40 /** Executor used to execute instances of this class */
41 private static final Executor executor
= Executors
.newSingleThreadExecutor();
42 /** Queue containing <code>ExecutableRunnable</code>s that should be retried */
43 private static final Queue
<ExecutableRunnable
> retryPendingTasks
= new LinkedList
<ExecutableRunnable
>();
45 /** Run all tasks that should be retried */
46 public static final void retryTasks(){
47 synchronized(retryPendingTasks
){
48 for(ExecutableRunnable task
: retryPendingTasks
)
50 retryPendingTasks
.clear();
54 /** Execute this <code>ExecutableRunnable</code> */
55 public final void execute(){
57 executor
.execute(this);
60 /** Mark this <code>ExecutableRunnable</code> as needing to be retried later */
61 protected final void retry(){
62 synchronized(retryPendingTasks
){
63 retryPendingTasks
.add(this);
This page took 0.045592 seconds and 4 git commands to generate.