官方文档对于ThreadPool的描写叙述是:ThreadPool is a Floodlight module wrapper for a Java's ScheduledExecutorService.  It can be used to
have threads be run at specific times or periodically. 所以仅仅要对并发编程有点基础,就非常easy理解。它实现了俩接口:1)IThreadPoolService规范的是得到ScheduledExecutorService的方法,2)IFloodlightModule则是将实现类作为模块来管理(默认启动)。优点是方便其它模块非常easy的指明依赖。看代码就非常easy明确。

public interface IThreadPoolService extends IFloodlightService
{
    /**
     * Get the master scheduled thread pool executor maintained by the
     * ThreadPool provider.  This can be used by other modules as a centralized
     * way to schedule tasks.
     * @return
     */
    public ScheduledExecutorService
getScheduledExecutor();
}

public interface IFloodlightModule
{
     
      /**
      * Return the list of interfaces that this module implements.
      * All interfaces must inherit IFloodlightService
      * @return
      */
     
      public Collection<Class<? extends IFloodlightService>>
getModuleServices();
     
      /**
      * Instantiate (as needed) and return objects that implement each
      * of the services exported by this module.  The map returned maps
      * the implemented service to the object.  The object could be the
      * same object or different objects for different exported services.
      * @return The
map from service interface class to service implementation
      */
      public Map<Class<? extends IFloodlightService>,
                IFloodlightService> getServiceImpls();
     
      /**
      * Get a list of Modules that this module depends on.  The module system
      * will ensure that each these dependencies is resolved before the
      * subsequent calls to init().
      * @return The
Collection of IFloodlightServices that this module depends
      *         on.
      */
     
      public Collection<Class<? extends IFloodlightService>>
getModuleDependencies();
     
      /**
      * This is a hook for each module to do its <em> internal</em> initialization,
      * e.g., call setService(context.getService("Service"))
      *
      * All module dependencies are resolved when this is called, but not every module
      * is initialized.
      *
      * @param context
      * @throws FloodlightModuleException
      */
     
      void init(FloodlightModuleContext
context) throws FloodlightModuleException;
     
      /**
      * This is a hook for each module to do its <em> external</em> initializations,
      * e.g., register for callbacks or
query for state in other modules
      *
      * It is expected that this function will not block and that modules that want
      * non - event
driven CPU will spawn their own threads.
      *
      * @param context
      */
     
      void startUp(FloodlightModuleContext
context);
}

public class ThreadPool implements IThreadPoolService,
IFloodlightModule {
      protected ScheduledExecutorService executor = null ;

      // IThreadPoolService
      @Override
      public ScheduledExecutorService
getScheduledExecutor() {
           return executor ;
     }

      // IFloodlightModule
      @Override
      public Collection<Class<? extends IFloodlightService>>
getModuleServices() {
          Collection<Class<? extends IFloodlightService>>
l = new ArrayList<Class<?

extends IFloodlightService>>();

          l.add(IThreadPoolService. class );
           return l;
     }

      @Override
      public Map<Class<?

extends IFloodlightService>,
IFloodlightService> getServiceImpls() {

          Map<Class<? extends IFloodlightService>,
IFloodlightService> m = new HashMap<Class<?

extends IFloodlightService>,
IFloodlightService>();

          m.put(IThreadPoolService. class , this );
           // We are the class that implements the
service
           return m;
     }

      @Override
      public Collection<Class<? extends IFloodlightService>>
getModuleDependencies() {
           // No dependencies
           return null ;
     }

      @Override
      public void init(FloodlightModuleContext
context)
               throws FloodlightModuleException
{
           executor =
Executors. newScheduledThreadPool(15);
           // parameter - the number of threads to
keep in the pool, even if they are idle.
     }

      @Override
      public void startUp(FloodlightModuleContext
context) {
           // no-op
     }
}




版权声明:本文博客原创文章,博客,未经同意,不得转载。

Floodlight controller 线程池模型的更多相关文章

  1. 基于java.util.logging实现轻量级日志记录库(增加根据当前类class初始化,修复线程池模型(javaEE)下的堆栈轨迹顺序与当前调用方法不一致问题)

    前言: 本章介绍自己写的基于java.util.logging的轻量级日志记录库(baseLog). 该版本的日志记录库犹如其名,baseLog,是个实现日志记录基本功能的小库,适合小型项目使用,方便 ...

  2. c++之初级的消息队列及线程池模型

    1.最近项目不是很忙,结合之前看的一些开源代码(skynet及其他github代码)及项目代码,抽空写了一个简单的任务队列当做练习. 2.介绍: 1)全局队列中锁的使用:多线程下,全局队列需要加锁,本 ...

  3. Netty源码解析一——线程池模型之线程池NioEventLoopGroup

    本文基础是需要有Netty的使用经验,如果没有编码经验,可以参考官网给的例子:https://netty.io/wiki/user-guide-for-4.x.html.另外本文也是针对的是Netty ...

  4. Dubbo学习笔记8:Dubbo的线程模型与线程池策略

    Dubbo默认的底层网络通讯使用的是Netty,服务提供方NettyServer使用两级线程池,其中 EventLoopGroup(boss) 主要用来接受客户端的链接请求,并把接受的请求分发给 Ev ...

  5. Nodejs事件引擎libuv源码剖析之:高效线程池(threadpool)的实现

    声明:本文为原创博文,转载请注明出处. Nodejs编程是全异步的,这就意味着我们不必每次都阻塞等待该次操作的结果,而事件完成(就绪)时会主动回调通知我们.在网络编程中,一般都是基于Reactor线程 ...

  6. Java 线程池框架核心代码分析--转

    原文地址:http://www.codeceo.com/article/java-thread-pool-kernal.html 前言 多线程编程中,为每个任务分配一个线程是不现实的,线程创建的开销和 ...

  7. MYSQL线程池总结(一)

    线程池是Mysql5.6的一个核心功能,对于服务器应用而言,无论是web应用服务还是DB服务,高并发请求始终是一个绕不开的话题.当有大量请求并发访问时,一定伴随着资源的不断创建和释放,导致资源利用率低 ...

  8. Linux下线程池的理解与简单实现

    首先,线程池是什么?顾名思义,就是把一堆开辟好的线程放在一个池子里统一管理,就是一个线程池. 其次,为什么要用线程池,难道来一个请求给它申请一个线程,请求处理完了释放线程不行么?也行,但是如果创建线程 ...

  9. [转]使用VC/MFC创建一个线程池

    许多应用程序创建的线程花费了大量时间在睡眠状态来等待事件的发生.还有一些线程进入睡眠状态后定期被唤醒以轮询工作方式来改变或者更新状态信息.线程池可以让你更有效地使用线程,它为你的应用程序提供一个由系统 ...

随机推荐

  1. 移动端 微信 网易 触屏滑动回弹菜单(css版)

    总结一下: 有点:网易新闻,微信 热文 都是 -webkit-overflow-scrolling: touch;实现,css实现,轻巧: bug: 部分安卓浏览器(uc,自带)  只支持持续滑动,不 ...

  2. Chromium-Dev一些缩写

    备案权 tl;dr: && TL;DR;  :"Too long;Don't read" PSA  :"Publice Service Announcem ...

  3. [6] 算法路 - 双向冒泡排序的Shaker

    Shaker序列 –算法 1. 气泡排序的双向进行,先让气泡排序由左向右进行.再来让气泡排序由右往左进行,如此完毕一次排序的动作 2. 使用left与right两个旗标来记录左右两端已排序的元素位置. ...

  4. C#分布式缓存Couchbase

    C#分布式缓存Couchbase使用 一.简介 目前C#业界使用得最多的 Cache 系统主要是 Memcached和 Redis. 这两个 Cache 系统可以说是比较成熟的解决方案,也是很多系统当 ...

  5. 关于cocos2dx导入安卓项目至eclipse的诸多问题

    看视频实在是有点蛋疼,尽管我也想在苹果上做,可是奈何自己是一个小屌丝,根本买不起高富帅的装备.所以仅仅能硬着头皮去处理win以下的问题. 在把用C++语言编写的cocos2dx项目编译编译完毕之后,导 ...

  6. IIS7安装场景对照表

    原文 IIS7安装场景对照表 Default Server Install Components Server Manager Update Name Static Content IIS-Stati ...

  7. Centos7系统配置上的变化(一)

    原文 Centos7系统配置上的变化(一) 安装后,一开始有点儿无力吐槽的感觉,变化这么大? 一.Runlevel 首先一条,原来一直用的CentOS-6.5-x86_64-minimal.iso光盘 ...

  8. uva 10228 - Star not a Tree?(模拟退火)

    题目链接:uva 10228 - Star not a Tree? 题目大意:给定若干个点,求费马点(距离全部点的距离和最小的点) 解题思路:模拟退火算法,每次向周围尝试性的移动步长,假设发现更长处, ...

  9. asp.net学习之GridView七种字段

    原文:asp.net学习之GridView七种字段 asp.net中GridView绑定到数据源时,可以自动显示数据源的各个字段.只要设定其AutoGenerateColumns为TRUE即可.但这, ...

  10. who is the best?

    Description There are N people want to choose the best person. Each person select the best person $a ...