Giter Site home page Giter Site logo

asyncall's Introduction

Java轻量级异步并行调用工具

基于java.util.concurrent线程池,主要做了如下简化或处理

轻量级:没有通过使用代理降低侵入性,因为那样有很多因素开发人员无法知道,增加复杂性和未知因素

// 三个任务A、B、C,其中C依赖A
// asyncall init
asyncallExecutor = AsyncallExecutor.createDefaultInstance();
asyncallExecutor.init();

// create execute unit
Asyncall asyncall = asyncallExecutor.createExecUnit();
final AsyncallFuture<Model> a = asyncall.exec(new Callable<Model>() {
    @Override
    public Model call() throws Exception {
        return dao.find(1000, "A");
    }
});
final AsyncallFuture<Model> b = asyncall.exec(new Callable<Model>() {
    @Override
    public Model call() throws Exception {
        return dao.find(1000, "b");
    }
});
final AsyncallFuture<Model> c = asyncall.exec(new Callable<Model>() {
    @Override
    public Model call() throws Exception {
        a.get();
        return dao.find(1000, "c");
    }
});
// hold 住等待执行完成
asyncall.await();

线程池初始化

AsyncallConfig AsyncallExecutor#init AsyncallExecutor#destory

异常处理

AsyncallExecutionHandler 默认处理:AsyncallExecutionHandler.DefaultPolic

...
@Override
public void handlerExecutionException(ExecutionException e) {
    Throwable ex = e.getCause();
    if (ex instanceof RuntimeException) {
        throw (RuntimeException) ex;
    } else {
        throw new AsyncallExecutionException(e);
    }
}
...

hold住异步线程等待执行完成

Asyncall#await();

threadlocal线程拷贝

谨慎使用,因为这样会打破原先ThreadLocal的语义,导致出现线程安全问题

public <V> AsyncallFuture<V> exec(Callable<V> callable, boolean threadLocalSupport)
public <V> AsyncallFuture<V> exec(Runnable runnable, boolean threadLocalSupport)

默认超时控制

AsyncallConfig#timeout

TODO

执行情况统计

asyncall's People

Contributors

larry4xie avatar

Watchers

teddy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.