官方文档对于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. python 2.x 与3.x的区别

    下载了点python的电子书,有基于3.x的有基于2.x的让我不知道看哪些好,BD一下差别着实很大有木有?print语句变成了函数有木有?之后都得加括号了有木有? 别人整理的成果,我就无耻地搬来借用啦 ...

  2. SQL开发中容易忽视的一些小地方(六)

    原文:SQL开发中容易忽视的一些小地方(六) 本文主旨:条件列上的索引对数据库delete操作的影响. 事由:今天在博客园北京俱乐部MSN群中和网友讨论了关于索引对delete的影响问题,事后感觉非常 ...

  3. CodeForces 441 A. Valera and Antique Items

    纯粹练JAVA.... A. Valera and Antique Items time limit per test 1 second memory limit per test 256 megab ...

  4. hdu 3683 Gomoku (模拟、搜索)

    Gomoku Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  5. Microsoft.AlphaImageLoader过滤评论

    Microsoft.AlphaImageLoader是IE滤镜的一种,其主要作用就是对图片进行透明处理.尽管FireFox和IE7以上的IE浏览器已经支持透明的PNG图片,可是就IE5-IE6而言还是 ...

  6. [Android]BaseExpandableListAdapter实现可折叠列表

    使用BaseExpandableListAdapter 以实现的可折叠的所谓列表,例如QQ朋友们在分组功能. 基于BaseExpandableListAdapter扩大ExpandableList说明 ...

  7. JMeter怎么在get URL请求、POST请求中添加动态参数用于服务器段安全验证

    从前一个页面(含有服务器段返回给客户端的参数,用于在下一次请求时验证)中添加后置处理器中的Regular Expression Extractor,使用正则表达式对参数进行提取. 在用到这些变量时可以 ...

  8. Android利用网络编程HttpClient批量上传(两)AsyncTask+HttpClient监测进展情况,并上传

    请尊重别人的劳动.转载请注明出处: Android网络编程之使用HttpClient批量上传文件(二)AsyncTask+HttpClient并实现上传进度监听 执行效果图: 我曾在<Andro ...

  9. react学习笔记2--练习Demos

    准备工作 # 0.react核心库 <script src="../build/react.js"></script> # 将JSX 语法转为 JavaSc ...

  10. 使用 CodeIgniter 框架快速开发 PHP 应用(二)

    原文:使用 CodeIgniter 框架快速开发 PHP 应用(二) 二分钟: 建立一个 CodeIgniter 网站用CI建一个网站很容易. 这一章很短,解释了用CI制作网站时发生了些什么,哪些文件 ...