Crossbow(LiteAsync) is an ameliorative, enhanced AsyncTask for Android. LiteAsync provides SimpleTask, SafeTask, CachedTask

Overview

android-lite-async

An ameliorative, enhanced AsyncTask for Android. LiteAsync provides SimpleTask, SafeTask, CachedTask, etc, for rapid development. More convenient is, it has a TaskExecutor which can executes ordered, cyclicbarrier, delayed and timer Task.

#同学们在日常开发中有没有遇到以下场景:

  1. 两个原子任务,任务2需要等待任务1完成了才能进行。
  2. 任务3需要等任务1和任务2都完成了才能进行,但是1和2可以并发以节省时间。看起来要写很多代码来调度任务。
  3. 服务器接口压力过大,要被你的调用频度调戏到down机啦!
  4. 系统的异步任务类AsyncTask要用的泛型太多太重啦,并且只能在主线程使用,不爽!
  5. 要么大量并发使手机cpu吃紧卡到爆,要么不能真正(Android系统自带AsyncTask)并发执行。不爽!

OK,如果你都遇到过,恭喜你,说明你的应用对开发者要求还是挺碉的。 那么是不是需要很多的代码才能完成这种和谐并发和任务调度呢?nooooo!有了Crossbow,我们只要一行代码。 比方说场景2, Task3要等待Task1,Task2执行完才能执行,我们使用LiteAsync可以这样做:

  TaskExecutor.newCyclicBarrierExecutor().put(task1).put(task2).start(task3);

这么一行代码,低调,内敛,而又充满能量,再多的任务可以执行,Task1,Task2并发执行,且随时可取消执行,结束(或取消)时会自动调度Task3执行。

#关于android并发 来谈谈并发,研究过Android系统源码的同学会发现:AsyncTask在android2.3的时候线程池是一个核心数为5线程,队列可容纳10线程,最大执行128个任务,这存在一个问题,当你真的有138个并发时,即使手机没被你撑爆,那么超出这个指标应用绝对crash掉。 后来升级到4.0,为了避免并发带来的一些列问题,AsyncTask竟然成为序列执行器了,也就是你即使你同时execute N个AsyncTask,它也是挨个排队执行的。 这一点请同学们一定注意,AsyncTask在4.0以后,是异步的没错,但不是并发的。

言归正传,我们来看看LiteAsync能做些什么吧:

#异步任务AsyncTask

  1. Ameliorative AsyncTask:真正可并发,均衡手机能力与开销,针对短时间大量并发有调控策略,可在子线程执行。
  2. SimpleTask:具备Ameliorative AsyncTask所有特性,简化了使用方法,仅设置一个泛型(结果类)即可。
  3. SafeTask:具备Ameliorative AsyncTask所有特性,但是各个环节是安全的,能捕获任何异常,并传递给开发者。
  4. CachedTask:具备Ameliorative AsyncTask所有特性,增加了对结果的缓存,可设置一个超时时间,只有在超时后才去异步执行,否则取缓存结果返回。

#任务调度器TaskExecutor

  1. 顺序执行器,使一系列异步任务按序执行,非并发
  2. 关卡执行器,使一系列异步任务并发执行,最后会调度执行一个终点任务
  3. 延迟执行器,使一个异步任务延迟开发者指定的时间后执行
  4. 心跳执行器,是一个异步任务按执行的间隔持续执行

恩,全部介绍完了,它很简单,却是最贴心的异步&并发爱心天使。 我在github工程里各自都谢了demo和案例,约10来个,足够你起步啦,现在就用起来吧骚年!

关于作者(About Author)

我的博客 :http://vmatianyu.cn

我的开源站点 :http://litesuits.com

点击加入QQ群: 42960650

47357508

我的论坛帖子

LiteHttp:极简且智能的 android HTTP 框架库 (专注于网络)

LiteOrm:极简且智能的 android ORM 框架库 (专注数据库)

LiteAsync:强势的 android 异步 框架库 (专注异步与并发)

LiteCommon:丰富通用的android工具类库(专注于基础组件)

我的博客帖子

关于java的线程并发和锁的总结

android开发技术经验总结60条

聚划算android客户端1期教训总结

移动互联网产品设计小结

You might also like...
A library provides some useful kotlin extension functions

ktext 🔥 A library provides some useful kotlin extension functions. Including in your project Gradle Add below codes to your root build.gradle file (n

This provides the javafx runtimes for windows, linux, and mac os x86 platforms for Ignition

ignition JavaFX Provider This provides the javafx runtimes for windows, linux, and mac os x86 platforms for Ignition Steps to use run gradlew build st

Kamper - a small KMM/KMP library that provides performance monitoring for your app.
Kamper - a small KMM/KMP library that provides performance monitoring for your app.

🎯 Kamper Kamper is a KMP/KMM library that implements a unified way to track application performances. The solution is based on plugin design patterns

Com.hhvvg.anytext - An application provides features to modify any TextView in any other applications

AnyText What's this This application provides features to modify any TextView in

Kotools Types - a lightweight library that provides commonly used types for Kotlin

Kotools Types is a lightweight library that provides commonly used types for Kotlin

Android MVVM framework write in kotlin, develop Android has never been so fun.

KBinding 中文版 Android MVVM framework write in kotlin, base on anko, simple but powerful. It depends on my another project AutoAdapter(A library for sim

Klimatic is an android app built using Kotlin. It try to showcase all the latest technologies used in android.
Klimatic is an android app built using Kotlin. It try to showcase all the latest technologies used in android.

Klimatic Klimatic is an android app built using Kotlin. It try to showcase all the latest technologies used in android. Built using Android Architectu

Oratio Library for Android Studio helps you simplify your Android TTS codes

Oratio Oratio is a library for Android Studio. This library is useful to a number of developers who are currently making apps using android TTS(Text-T

This is a demo android app representing implementation of SE principles in android app development

Articles Demo This repository contains a sample Android App that shows most popular articles data from NY Times API. This is a sample app that shows h

Comments
  • 无法将类 AsyncTask<Params,Progress,Result>中的方法 execute应用到给定类型

    无法将类 AsyncTask中的方法 execute应用到给定类型

    我是把library导入到Android Studio里,报了这个异常:

    Error:(76, 21) 错误: 无法将类 AsyncTask<Params,Progress,Result>中的方法 execute应用到给定类型; 需要: CAP#1[] 找到: 没有参数 原因: 形式 varargs 元素类型CAP#1无法从 类 <匿名com.litesuits.android.async.TaskExecutor$1> 进行访问 其中, Params,Progress,Result是类型变量: Params扩展已在类 AsyncTask中声明的Object Progress扩展已在类 AsyncTask中声明的Object Result扩展已在类 AsyncTask中声明的Object 其中, CAP#1是新类型变量: CAP#1从?的捕获扩展Object

    opened by Pigcasso 3
  • Error:(76, 21) 错误: 无法将类 AsyncTask<Params,Progress,Result>中的方法 execute应用到给定类型;……

    Error:(76, 21) 错误: 无法将类 AsyncTask中的方法 execute应用到给定类型;……

    Error:(76, 21) 错误: 无法将类 AsyncTask<Params,Progress,Result>中的方法 execute应用到给定类型; 需要: CAP#1[] 找到: 没有参数 原因: 形式 varargs 元素类型CAP#1无法从 类 <匿名com.litesuits.android.async.TaskExecutor$1> 进行访问 其中, Params,Progress,Result是类型变量: Params扩展已在类 AsyncTask中声明的Object Progress扩展已在类 AsyncTask中声明的Object Result扩展已在类 AsyncTask中声明的Object 其中, CAP#1是新类型变量: CAP#1从?的捕获扩展Object

    opened by gzu-liyujiang 1
Owner
马天宇
welcome to http://litesuits.com
马天宇
Clay is an Android library project that provides image trimming which is originally an UI component of LINE Creators Studio

Clay Clay is an Android library project that provides image trimming. Fully written in Kotlin, Clay is originally a UI component of LINE Creators Stud

LINE 119 Dec 27, 2022
An Android Library that provides social login for 15 platforms within by RxJava2, Kotlin and Firebase Authentication.

RxSocialLogin The license information for logo is located at the bottom of the document. These instructions are available in their respective language

WindSekirun (wind.seo) 124 Nov 21, 2022
Simple Android Library, that provides easy way to start the Activities with arguments.

Warning: Library is not maintained anymore. If you want to take care of this library, propose it via Pull Request. It needs adjustmensts for newer ver

Marcin Moskała 429 Dec 15, 2022
An android application developed in Kotlin that provides lists and tables of soccer leagues through api consumption

An android application developed in Kotlin that provides lists and tables of soccer leagues through api consumption

Paulo César 4 May 16, 2022
An android lib that provides most commonly used utility function

Awesome-Utility An android lib that provides most commonly used utility function. It can help Android developers with supporting common utility functi

Ameer Hamza 2 Apr 5, 2022
This library provides common speech features for ASR including MFCCs and filterbank energies for Android and iOS.

Kotlin Speech Features Quick Links ?? Introduction This library is a complete port of python_speech_features in pure Kotlin available for Android and

Merlyn Mind 13 Oct 7, 2022
AbstractMvp 0.8 0.0 Kotlin is a library that provides abstract components for MVP architecture realization, with problems solutions that are exist in classic MVP.

MinSDK 14+ AbstractMvp AbstractMvp is a library that provides abstract components for MVP architecture realization, with problems solutions that are e

Robert 12 Apr 5, 2022
Andorid app which provides a bunch of useful Linux commands.

Linux Command Library for Android The app currently has 3203 manual pages, 1351 one-line scripts and a bunch of general terminal tips. It works 100% o

Simon Schubert 276 Dec 31, 2022
Provides Kotlin libs and some features for building Kotlin plugins

Kotlin Plugin Provides Kotlin libs and some features for building awesome Kotlin plugins. Can be used instead of CreeperFace's KotlinLib (don't use to

null 3 Dec 24, 2021
Provides metadata for networkIDs and chainIDs

The source data is in _data/chains. Each chain has its own file with the filename being the CAIP-2 representation as name and .json ans extension.

null 4.1k Jan 9, 2023