官方文档对于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. machine learn in python 第二章2.1.1

    1大约 sklearn.datasets from sklearn.datasets import load_iris import numpy as np data = load_iris() da ...

  2. POJ 3579- Median

     Description Given N numbers, X1, X2, ... , XN, let us calculate the difference of every pair of n ...

  3. IOS 数据库管理系统(SQLite)

    嵌入式数据库 SQLite嵌入式数据库的优势 1.支持事件,你并不需要配置,无需安装,不需要管理员 2.支持部分脂肪SQL92 3.完整的数据库被存储在磁盘上的文件的顶部,相同的数据库文件可以在不同机 ...

  4. Partitioner分区过程分析

    Partition中国人意味着分区,意义的碎片,这个阶段也是整个MapReduce该过程的第三阶段.在Map返回任务,是使key分到通过一定的分区算法.分到固定的区域中.给不同的Reduce做处理,达 ...

  5. WPF六个控制概述

    在线演示:http://v.youku.com/v_show/id_XNzA0NjU1Mjk2.html 清晰版视频+代码下载:http://115.com/lb/5lbcftnrfo9s 一.简单介 ...

  6. HDU1069_Monkey and Banana【LCS】

    Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  7. BZOJ 2115 Wc2011 Xor DFS+高斯消元

    标题效果:鉴于无向图.右侧的每个边缘,求一个1至n路径,右上路径值XOR和最大 首先,一个XOR并能为一个路径1至n简单的路径和一些简单的XOR和环 我们开始DFS获得随机的1至n简单的路径和绘图环所 ...

  8. web架构设计经验分享(转)

    本人作为一位web工程师,着眼最多之处莫过于 性能与架构,本次幸得参与sd2.0大会,得以与同行广泛交流,于此二方面,有些心得,不敢独享,与众博友分享,本文是这次参会与众同撩交流的心得,有兴趣者可以查 ...

  9. Notification使用以及PendingIntent.getActivity() (转)

    public void sendNotification(Context ctx,String message) { //get the notification manager String ns ...

  10. java.lang.Runnable接口

    大家都知道使用线程的2种方式,一是继承Thread类,二是实现Runnable接口.实际上,即使你实现了Runnable接口,终于还是要构造一个Thread类的对象.看过Thread源码发现,事实上这 ...