Git Product home page Git Product logo

geekthread's Introduction

GeekThread

Android ThreadPool的封装

使用方法

在项目的build.gradle里面加上引用:

compile 'com.geek.thread:thread-pool:1.0.1'

方法说明

GeekThreadManager.getInstance().execute(new GeekRunnable(ThreadPriority.LOW) {
    @Override
    public void run() {
        // do something
    }
}, ThreadType.NORMAL_THREAD);

通过传入Runable的方式来使用多线程,其中ThreadPriority.LOW表示线程级别,ThreadType.NORMAL_THREAD表示线程类型。

GeekThreadManager.getInstance().execute(new GeekThread(ThreadPriority.NORMAL) {
    @Override
    public void run() {
        super.run();
          // do something
    }
},ThreadType.NORMAL_THREAD);

这个使用方法与上面的类似,只是传入的Runable换成了Thread

GeekThreadPools.executeWithGeekThreadPool(new Runnable() {
    @Override
    public void run() {
        //do something
    }
});

直接扔进去一个普通的Runable,线程级别和类型都为普通的。

总结

这个框架主要的作用是内部帮我们实现了线程池,维护了多线程,我们只需要在使用的地方调用就可以了,无需担心因为多出调用多线程而导致的内存消耗等问题,也不需要每次都去实现一个线程池。

geekthread's People

Contributors

onlyterminator avatar

Watchers

xiangyutian 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.