官方文档对于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. CVE-2014-4113:飓风熊猫(HURRICANE PANDA)Win64bit提起权0day破绽

    飓风熊猫被觉得是原产于中国.主要针对基础设施公司的先进攻击者.我们知道它们除了拥有0day漏洞外.还有其它的三种本地特权提升漏洞.我们知道飓风熊猫使用的是"ChinaChopper" ...

  2. 缓存之EHCache(转)

    一.简介非常简单,而且易用. ehcache 是一个非常轻量级的缓存实现,而且从1.2 之后就支持了集群,而且是hibernate 默认的缓存provider.ehcache 是一个纯Java的进程内 ...

  3. HDU 1026 Ignatius and the Princess I 迷宫范围内的搜索剪枝问题

    这个问题是一个典型的类型的问题迷宫广泛的搜索. 在网上看到了很多解决方案. 没什么解决问题的分析报告,不指出其中的关键点.代码更像是一大抄.一些分析师也有很大的文章分析.只是不要全部命中关键,什么是广 ...

  4. LeetCode :: Insertion Sort List [具体分析]

    Sort a linked list using insertion sort. 仍然是一个很简洁的题目,让我们用插入排序给链表排序:这里说到插入排序.能够来回想一下, 最主要的入门排序算法.就是插入 ...

  5. Android开发人员官方站点文档 - 国内踏得网镜像

    Android Developer 安卓开发人员官方站点无法正常訪问.即使FQ因为网络原因依旧訪问缓慢. 故整理相关字体.脚本.样式.页面资源,在踏得网server上建立了本地镜像.初始镜像时间201 ...

  6. JavaScript面向对象旅程(下)

    JavaScript面向对象旅程 剪不断,理还乱,是离愁. 前面已经提到过新语言开发的两个步骤,分别是:一.定义基本的数据类型,完善结构化编程语言的设计:二.为函数类型绑定this的概念,好在对象的方 ...

  7. Qt原始资源形象问题后删除

        这些天Qt请项目超市收银系统,作为练一练手,无论如何,亦休闲亦无关,做几乎同样的.旨在取代以前的资源图片, 是什么改变了,码里面的路径都改了.还是编译只是去,总是提示这样一个错误. <s ...

  8. Windows 2008 卸载 IIS7 批处理

    @echo offcolor 0aecho 正在卸载IIS功能,这可能需要几分钟时间...start /w pkgmgr /uu:IIS-WebServerRole;WAS-WindowsActiva ...

  9. Oracle按不同时间分组统计

    Oracle按不同时间分组统计 Oracle按不同时间分组统计的sql 如下表table1: 日期(exportDate) 数量(amount) -------------- ----------- ...

  10. 系统ls命令出现1;2cl;2cl;2cl;2c(转)

    1;2c after using cat or more on binary filesI noticed that if you use the hex 05 in a file and cat o ...