MCPcopy Index your code
hub / github.com/SilenceDut/AsyncTaskScheduler

github.com/SilenceDut/AsyncTaskScheduler @v1.0.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.1 ↗ · + Follow
44 symbols 83 edges 8 files 10 documented · 23%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Deprecated

using TaskScheduler highly recommend

AsyncTaskScheduler

Background

详细解读AsyncTask的黑暗面以及一种替代方案

Characters

  • execute tasks in parallel as default, rather than processing them sequentially
  • execute single task use a thread rather than an executor
  • you can set a default executor to execute tasks
  • a callback for task error
  • manage multiple tasks easily
  • you can you it on any thread ,anf it will have a callback on main thread。

Methods Introduction

methods like AsyncTask ,use easily

  • doInBackground : background thread
  • onProgressUpdate : main thread
  • onExecuteSucceed : main thread
  • onExecuteCancelled : main thread
  • onExecuteFailed : main thread,when unexpected happened

Add to project

latest-version:

Step 1. Add the JitPack repository to your build file

gradle

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

maven

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Step 2. Add the dependency

gradle

compile 'com.github.SilenceDut:AsyncTaskScheduler:{latest-version}'

maven

<dependency>
    <groupId>com.github.SilenceDut</groupId>
    <artifactId>AsyncTaskScheduler</artifactId>
    <version>{latest-version}</version>
</dependency>

How to use

Single background task ,use a single thread rather than an Executor, save resource

SingleAsyncTask singleTask = new SingleAsyncTask<Void,String>() {   
   @Override    
   public String doInBackground() {   
       return null;   
   }
   @Override
   public void onExecuteSucceed(String result) {      
       super.onExecuteSucceed(result);      
   }
   @Override
   public void onExecuteFailed(Exception exception) {      
       super.onExecuteFailed(exception);    
       Log.i(TAG,"onExecuteCancelled:"+exception.getMessage()+Thread.currentThread());
   }
};
singleTask.executeSingle();

//取消通过executeSingle执行的任务
mSingleAsyncTask.cancel(true);

multiple background tasks,create a task scheduler to manage them.

//多个任务新建一个任务调度器
AsyncTaskScheduler mAsyncTaskScheduler = new AsyncTaskScheduler();

SingleAsyncTask singleTask1 = new  SingleTask() { ... };
SingleAsyncTask singleTask2 = new  SingleTask() { ... };
SingleAsyncTask singleTask3 = new  SingleTask() { ... };
...

//并行执行多个任务
mAsyncTaskScheduler.execute(singleTask1)
.execute(singleTask2).execute(singleTask3).

 //取消通过AsyncTaskScheduler任务
mAsyncTaskScheduler.cancelAllTasks(true);

you can set a default Executor to execute tasks

//设置默认的线程池
Executor defaultPoolExecutor = ...
AsyncTaskScheduler mAsyncTaskScheduler = new AsyncTaskScheduler(Executor defaultPoolExecutor);

make sure cancel task to avoid memory leak

//取消通过executeSingle执行的任务
mSingleAsyncTask.cancel(true);

//取消通过AsyncTaskScheduler任务
mAsyncTaskScheduler.cancelAllTasks(true);

License

Copyright 2015-2016 SilenceDut

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Core symbols most depended-on inside this repo

execute
called by 2
library/src/main/java/com/silencedut/asynctaskscheduler/AsyncTaskScheduler.java
cancel
called by 2
library/src/main/java/com/silencedut/asynctaskscheduler/SingleAsyncTask.java
isCancelled
called by 2
library/src/main/java/com/silencedut/asynctaskscheduler/SingleAsyncTask.java
cancelTask
called by 1
library/src/main/java/com/silencedut/asynctaskscheduler/AsyncTaskScheduler.java
cancelAllTasks
called by 1
library/src/main/java/com/silencedut/asynctaskscheduler/AsyncTaskScheduler.java
executeSingle
called by 1
library/src/main/java/com/silencedut/asynctaskscheduler/SingleAsyncTask.java
postResult
called by 1
library/src/main/java/com/silencedut/asynctaskscheduler/SingleAsyncTask.java
getFutureTask
called by 1
library/src/main/java/com/silencedut/asynctaskscheduler/SingleAsyncTask.java

Shape

Method 34
Class 10

Languages

Java100%

Modules by API surface

library/src/main/java/com/silencedut/asynctaskscheduler/SingleAsyncTask.java21 symbols
app/src/main/java/com/silencedut/asynctaskschedulertest/MainActivity.java7 symbols
library/src/main/java/com/silencedut/asynctaskscheduler/AsyncTaskScheduler.java6 symbols
library/src/test/java/com/silencedut/asynctaskscheduler/ExampleUnitTest.java2 symbols
library/src/androidTest/java/com/silencedut/asynctaskscheduler/ExampleInstrumentationTest.java2 symbols
app/src/test/java/com/silencedut/asynctaskschedulertest/ExampleUnitTest.java2 symbols
app/src/main/java/com/silencedut/asynctaskschedulertest/App.java2 symbols
app/src/androidTest/java/com/silencedut/asynctaskschedulertest/ExampleInstrumentationTest.java2 symbols

For agents

$ claude mcp add AsyncTaskScheduler \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact