- 浏览: 987713 次
文章分类
- 全部博客 (428)
- Hadoop (2)
- HBase (1)
- ELK (1)
- ActiveMQ (13)
- Kafka (5)
- Redis (14)
- Dubbo (1)
- Memcached (5)
- Netty (56)
- Mina (34)
- NIO (51)
- JUC (53)
- Spring (13)
- Mybatis (17)
- MySQL (21)
- JDBC (12)
- C3P0 (5)
- Tomcat (13)
- SLF4J-log4j (9)
- P6Spy (4)
- Quartz (12)
- Zabbix (7)
- JAVA (9)
- Linux (15)
- HTML (9)
- Lucene (0)
- JS (2)
- WebService (1)
- Maven (4)
- Oracle&MSSQL (14)
- iText (11)
- Development Tools (8)
- UTILS (4)
- LIFE (8)
最新评论
-
Donald_Draper:
Donald_Draper 写道刘落落cici 写道能给我发一 ...
DatagramChannelImpl 解析三(多播) -
Donald_Draper:
刘落落cici 写道能给我发一份这个类的源码吗Datagram ...
DatagramChannelImpl 解析三(多播) -
lyfyouyun:
请问楼主,执行消息发送的时候,报错:Transport sch ...
ActiveMQ连接工厂、连接详解 -
ezlhq:
关于 PollArrayWrapper 状态含义猜测:参考 S ...
WindowsSelectorImpl解析一(FdMap,PollArrayWrapper) -
flyfeifei66:
打算使用xmemcache作为memcache的客户端,由于x ...
Memcached分布式客户端(Xmemcached)
Tomcat的Server初始化及启动过程:http://donald-draper.iteye.com/blog/2327060
来看StandardThreadExecutor
//查看TaskQueue
//查看TaskThreadFactory
查看ThreadPoolExecutor
总结:Service启动,所做的事情,就是创建线程执行器
public class StandardService extends LifecycleMBeanBase implements Service { private static final String info = "org.apache.catalina.core.StandardService/1.0"; private String name = null; private static final StringManager sm = StringManager.getManager(Constants.Package); private Server server = null; protected Connector connectors[] = new Connector[0]; private final Object connectorsLock = new Object(); protected ArrayList<Executor> executors = new ArrayList<Executor>(); protected Container container = null; private ClassLoader parentClassLoader = null; // Initialize any Executors protected void initInternal() throws LifecycleException { for (Executor executor : findExecutors()) { if (executor instanceof LifecycleMBeanBase) { ((LifecycleMBeanBase) executor).setDomain(getDomain()); } executor.init(); } } protected void startInternal() throws LifecycleException { synchronized (executors) { for (Executor executor: executors) { //启动executor executor.start(); } } } }
来看StandardThreadExecutor
public class StandardThreadExecutor extends LifecycleMBeanBase implements Executor, ResizableExecutor { // ---------------------------------------------- Properties /** * Default thread priority */ protected int threadPriority = Thread.NORM_PRIORITY; /** * Run threads in daemon or non-daemon state */ protected boolean daemon = true; /** * Default name prefix for the thread name */ protected String namePrefix = "tomcat-exec-"; /** * max number of threads */ protected int maxThreads = 200; /** * min number of threads */ protected int minSpareThreads = 25; /** * idle time in milliseconds */ protected int maxIdleTime = 60000; /** * The executor we use for this component */ protected ThreadPoolExecutor executor = null; /** * the name of this thread pool */ protected String name; /** * The maximum number of elements that can queue up before we reject them */ protected int maxQueueSize = Integer.MAX_VALUE; private TaskQueue taskqueue = null; //初始化、调用父类的initInternal,注册到Mbean到JVM protected void initInternal() throws LifecycleException { super.initInternal(); } /** * Start the component and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ //启动 protected void startInternal() throws LifecycleException { //创建任务队列 taskqueue = new TaskQueue(maxQueueSize); //创建任务线程工厂 TaskThreadFactory tf = new TaskThreadFactory(namePrefix,daemon,getThreadPriority()); //创建线程执行器 executor = new ThreadPoolExecutor(getMinSpareThreads(), getMaxThreads(), maxIdleTime, TimeUnit.MILLISECONDS,taskqueue, tf); executor.setThreadRenewalDelay(threadRenewalDelay); if (prestartminSpareThreads) { executor.prestartAllCoreThreads(); } taskqueue.setParent(executor); setState(LifecycleState.STARTING); }
//查看TaskQueue
/** * As task queue specifically designed to run with a thread pool executor. * The task queue is optimised to properly utilize threads within * a thread pool executor. If you use a normal queue, the executor will spawn threads * when there are idle threads and you wont be able to force items unto the queue itself * */ TaskQueue继承了LinkedBlockingQueue public class TaskQueue extends LinkedBlockingQueue<Runnable> { private ThreadPoolExecutor parent = null; // no need to be volatile, the one times when we change and read it occur in // a single thread (the one that did stop a context and fired listeners) private Integer forcedRemainingCapacity = null; @Override //如果可能的话,将Runnable加到BlockingQueue里,即如果BlockingQueue可以容纳,则返回true,否则返回false。 public boolean offer(Runnable o) { //we can't do any checks if (parent==null) return super.offer(o); //we are maxed out on threads, simply queue the object if (parent.getPoolSize() == parent.getMaximumPoolSize()) return super.offer(o); //we have idle threads, just add it to the queue if (parent.getSubmittedCount()<(parent.getPoolSize())) return super.offer(o); //if we have less threads than maximum force creation of a new thread if (parent.getPoolSize()<parent.getMaximumPoolSize()) return false; //if we reached here, we need to add it to the queue return super.offer(o); } @Override //获取并移除此队列的头Runnable,若不能立即取出,则可以等time参数规定的时间,取不到时返回null。 public Runnable poll(long timeout, TimeUnit unit) throws InterruptedException { Runnable runnable = super.poll(timeout, unit); if (runnable == null && parent != null) { // the poll timed out, it gives an opportunity to stop the current // thread if needed to avoid memory leaks. parent.stopCurrentThreadIfNeeded(); } return runnable; } @Override //获取BlockingQueue里排在首位的对象Runnable,若BlockingQueue为空,阻断进入等待状态直到BlockingQueue有新的对象被加入为止 public Runnable take() throws InterruptedException { if (parent != null && parent.currentThreadShouldBeStopped()) { return poll(parent.getKeepAliveTime(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS); // yes, this may return null (in case of timeout) which normally // does not occur with take() // but the ThreadPoolExecutor implementation allows this } return super.take(); } }
//查看TaskThreadFactory
/** * Simple task thread factory to use to create threads for an executor implementation. */ public class TaskThreadFactory implements ThreadFactory { private final ThreadGroup group; private final AtomicInteger threadNumber = new AtomicInteger(1); private final String namePrefix; private final boolean daemon; private final int threadPriority; public TaskThreadFactory(String namePrefix, boolean daemon, int priority) { SecurityManager s = System.getSecurityManager(); group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup(); this.namePrefix = namePrefix; this.daemon = daemon; this.threadPriority = priority; } @Override public Thread newThread(Runnable r) { TaskThread t = new TaskThread(group, r, namePrefix + threadNumber.getAndIncrement()); t.setDaemon(daemon); t.setPriority(threadPriority); return t; } }
查看ThreadPoolExecutor
ThreadPoolExecutor继承了java.util.concurrent.ThreadPoolExecutor public class ThreadPoolExecutor extends java.util.concurrent.ThreadPoolExecutor {}
总结:Service启动,所做的事情,就是创建线程执行器
发表评论
-
tomcat日志及log4j日志乱码
2017-04-26 15:00 5509Linux系统字符编码:http://www.cnblogs. ... -
SQL盲注的解决方案
2016-10-27 18:35 2570引起SQL盲注的原因:http://www-01.ibm.co ... -
Tomcat的HTTPS配置详解
2016-10-27 16:59 978HTTPS原理详解:http://blog.csdn.net/ ... -
Tomcat的JioEndPoint,处理HTTP请求
2016-10-12 19:02 1270Tomcat的Connector(Protocol,Coyot ... -
Tomcat的Connector(Protocol,CoyoteAdapterAdapter,AprEndPoint)初始化及请求处理过程
2016-10-12 16:46 1640Tomcat的Server初始化及启动过程:http://do ... -
Tomcat问题集
2016-10-09 17:50 836tcnative-1.dll: Can't load AMD ... -
Tomcat-ConfigContext监听器(Context.xml,web.xml)
2016-09-27 12:59 1989Tomcat的Host初始化(Context,Listener ... -
Tomcat的Host初始化(Context,Listener,Filter,Servlet)
2016-09-27 08:42 1507Tomcat的Engine初始化,启动过程:http://do ... -
Tomcat的Engine初始化,启动过程
2016-09-26 15:33 2308Tomcat的Server初始化及启动过程:http://do ... -
Tomcat的Server初始化及启动过程
2016-09-26 11:02 2944Tomcat7,启动过程(BootStrap、Catalina ... -
Tomcat7,启动过程(BootStrap、Catalina)
2016-09-23 19:08 1878Tomcat 系统架构与设计模式,工作原理:http://ww ... -
405 request method post not supported
2016-08-18 18:09 32381.检查链接地址有没有错误 2.看RequestMethod, ... -
apache-tomcat-7.0.67\bin\tcnative-1.dll: Can't load AMD 64-bit .dll on a IA 3
2016-08-12 13:02 1148F:\apache-tomcat-7.0.67\bin\tcn ...
相关推荐
- **服务器初始化**:通过`getServer().setCatalina(this)`设置`Catalina`对象与服务器对象之间的关联,然后调用`getServer().init()`进行初始化。 6. **StandardServer初始化**: - 在`init`方法中,遍历所有的...
从 `Bootstrap` 类开始,逐步初始化类加载器、加载配置文件,直到启动服务器并监听端口,最终形成一个完整的 Tomcat 启动过程。这一过程不仅揭示了 Tomcat 内部工作原理,也为进一步理解和优化 Tomcat 配置提供了...
Lifecycle接口用于统一管理组件的生命周期,包括初始化、启动、停止和销毁等状态的转换。这是Tomcat中的一个重要设计模式,它使得组件的生命周期管理变得清晰和一致。Lifecycle接口由StandardService类实现,...
在Tomcat7的启动过程中,涉及到很多内部组件的初始化,其中`Digester`是一个重要的工具,用于解析XML配置文件,将XML结构映射为Java对象。本篇文章将深入剖析`Digester`的使用以及它在Tomcat7启动过程中的作用。 `...
- **Bootstrap**: Tomcat启动的入口点,负责初始化Catalina。 - **Catalina**: Tomcat的核心组件之一,主要负责管理整个服务器的生命周期。 - **StandardServer**: 表示一个完整的Tomcat实例,包括所有服务和服务器...
- 维护所有`Service`组件的生命周期,包括初始化、终结、定位与查找。 - **类结构**: - `Server`接口的标准实现类为`StandardServer`。 - `StandardServer`实现了所有`Server`接口方法。 - 关键方法`addService...
1. `Catalina`:Tomcat的核心,负责启动、初始化和管理Web应用。`StandardServer`、`StandardService`、`StandardEngine`、`StandardHost`和`StandardContext`等类构建了容器层次结构。 2. `Connector`:负责与...
Server组件负责整个Tomcat的初始化、启动和关闭,它是整个Tomcat的控制中心。 在Tomcat架构中,组件之间的通信和交互是通过事件监听和广播机制来实现的。这种方式同样体现了设计模式中的观察者模式,当一个组件的...
2010-8-11 18:24:13 org.apache.catalina.core.AprLifecycleListener lifecycleEvent 信息: The Apache Tomcat Native library which allows optimal performance in production environments ...再启动tomcat,一切okay
3. **组件初始化与启动**: - `server.initialize()`初始化Server组件。 - `((Lifecycle)server).start()`启动Server组件,这里通过`Lifecycle`接口调用`start()`方法。 - 通知所有注册的组件`server`已启动,...
- **生命周期管理**:Tomcat组件遵循特定的生命周期接口,如Lifecycle和ManagedBean,它们定义了启动、停止、初始化和销毁等阶段。 - **容器模型**:Tomcat使用容器的概念来管理Web应用和组件,每个容器都可以包含子...
Tomcat中的组件都遵循一个标准的生命周期,包括初始化、启动、暂停、停止和销毁。`Lifecycle`接口和`LifecycleListener`接口定义了这个过程。 6. **部署与加载** Tomcat使用`org.apache.catalina.deploy`和`org....
《Tomcat系统架构与模式设计分析》 Tomcat,作为一款广泛应用的Java Servlet容器,其系统架构和模式设计对于理解其高效稳定运行至关重要。本文将深入探讨Tomcat的核心组件、结构以及关键设计模式。 首先,Tomcat的...
**启动流程**,Tomcat的启动始于`Bootstrap`类,这是程序的入口点,它初始化并调用`Catalina`类。`Catalina`进一步启动`StandardServer`和`StandardService`。启动过程中,`Lifecycle`接口和模板方法模式起到了关键...
- 内部还包含`StandardService`的初始化。 4. **StandardService类**: - 初始化`Connectors`,创建适配器`CoyoteAdapter`并与`Http11Protocol`关联。 5. **Http11Protocol类**: - 设置适配器,并初始化协议...
这些组件遵循Java的生命周期管理,如初始化、启动、停止和销毁等阶段。 - “conf”目录下的server.xml文件是Tomcat的主要配置文件,用于定义服务器的全局设置,如Connector(监听端口)和Context(Web应用上下文)...
深入到源码层面,Catalina的核心类`org.apache.catalina.core.StandardServer`负责服务器的初始化和关闭。它继承自`Lifecycle`接口,并实现了一系列的生命周期方法,如`start()`和`stop()`,确保Tomcat的正确启动和...
- `org.apache.catalina.startup.Bootstrap`:Tomcat的启动入口,负责加载服务器配置并初始化Catalina。 - `org.apache.catalina.core.StandardServer`:服务器对象,管理其他服务器组件。 - `org.apache....