允许多个子线程的Asynctak MultiAsynctask

码农软件 · 软件分类 · 手机开发工具 · 2019-04-30 14:13:04

软件介绍

MultiAsynctask,相当于Asynctak,核心不同。系统的AsyncTask在不同版本的API的并发策略是不同的,在Android4.0以上只能运行一个Asynctask。Multiasynctask可以同时做更多的子线程做的事情。默认为5个,且线程池的线程个数是可以修改的。

使用方式如下,基本和系统API相同:

public class LongAsynctask extends MultiAsynctask<Paramer, Updater, Resulter> {

    @Override
    public void onPrepare() {
    }

    @Override
    public Resulter onTask(Paramer... params) {
        Paramer paramer = params[0];
        Logger.i("onTask打印:" + "what:" + paramer.getWhat() + ";value:" + paramer.getValue());
        for (int i = 0; i < 10; i++) {
            paramer.setValue(paramer.getValue() + 1);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            Updater updater = new Updater(paramer.getWhat(), paramer.getValue());
            postUpdate(updater);
        }
        return new Resulter(paramer.getWhat(), paramer.getValue());
    }

    @Override
    public void onUpdate(Updater update) {
        Logger.i("onUpdate打印:" + "what:" + update.getWhat() + ";value:" + update.getValue());
    }

    @Override
    public void onResult(Resulter result) {
        Logger.i("onResult打印:" + "what:" + result.getWhat() + ";value:" + result.getValue());
    }
}

本文地址:https://codercto.com/soft/d/4717.html

Complexity and Approximation

Complexity and Approximation

G. Ausiello、P. Crescenzi、V. Kann、Marchetti-sp、Giorgio Gambosi、Alberto M. Spaccamela / Springer / 2003-02 / USD 74.95

This book is an up-to-date documentation of the state of the art in combinatorial optimization, presenting approximate solutions of virtually all relevant classes of NP-hard optimization problems. The......一起来看看 《Complexity and Approximation》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试