tomcat源码 Connector

Connector容器主要负责解析socket请求,在tomcat中的源码位于org.apache.catalina.connector和org.apache.coyote包路径下;通过上两节的分析,我们知道了Connector是Service的子容器,而Service又是Server的子容器。在server.xml文件中配置,然后在Catalina类中通过Digester完成实例化。在server.xml中默认配置了两种Connector的实现,分别用来处理Http请求和AJP请求。
Connector的实现一共有以下三种:

1、Http Connector:解析HTTP请求,又分为BIO Http Connector和NIO Http Connector,即阻塞IO Connector和非阻塞IO Connector。本文主要分析NIO Http Connector的实现过程。

2、AJP:基于AJP协议,用于Tomcat与HTTP服务器通信定制的协议,能提供较高的通信速度和效率。如与Apache服务器集成时,采用这个协议。

3、APR HTTP Connector:用C实现,通过JNI调用的。主要提升对静态资源(如HTML、图片、CSS、JS等)的访问性能。

具体要使用哪种Connector可以在server.xml文件中通过protocol属性配置如下:

    <Connector port="8080" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443" />

然后看一下Connector的构造器:

public Connector(String protocol) {setProtocol(protocol);// Instantiate protocol handlerProtocolHandler p = null;try {Class<?> clazz = Class.forName(protocolHandlerClassName);p = (ProtocolHandler) clazz.getConstructor().newInstance();} catch (Exception e) {log.error(sm.getString("coyoteConnector.protocolHandlerInstantiationFailed"), e);} finally {this.protocolHandler = p;}if (Globals.STRICT_SERVLET_COMPLIANCE) {uriCharset = StandardCharsets.ISO_8859_1;} else {uriCharset = StandardCharsets.UTF_8;}
}public void setProtocol(String protocol) {boolean aprConnector = AprLifecycleListener.isAprAvailable() &&AprLifecycleListener.getUseAprConnector();if ("HTTP/1.1".equals(protocol) || protocol == null) {if (aprConnector) {setProtocolHandlerClassName("org.apache.coyote.http11.Http11AprProtocol");} else {setProtocolHandlerClassName("org.apache.coyote.http11.Http11NioProtocol");}} else if ("AJP/1.3".equals(protocol)) {if (aprConnector) {setProtocolHandlerClassName("org.apache.coyote.ajp.AjpAprProtocol");} else {setProtocolHandlerClassName("org.apache.coyote.ajp.AjpNioProtocol");}} else {setProtocolHandlerClassName(protocol);}
}

通过分析Connector构造器的源码可以知道,每一个Connector对应了一个protocolHandler,一个protocolHandler被设计用来监听服务器某个端口的网络请求,但并不负责处理请求(处理请求由Container组件完成)。下面就以Http11NioProtocol为例分析Http请求的解析过程。
在Connector的startInterval方法中启动了protocolHandler,代码如下:

protected void startInternal() throws LifecycleException {// Validate settings before startingif (getPort() < 0) {throw new LifecycleException(sm.getString("coyoteConnector.invalidPort", Integer.valueOf(getPort())));}setState(LifecycleState.STARTING);try {protocolHandler.start();} catch (Exception e) {throw new LifecycleException(sm.getString("coyoteConnector.protocolHandlerStartFailed"), e);}
}

Http11NioProtocol创建一个org.apache.tomcat.util.net.NioEndpoint实例,然后将监听端口并解析请求的工作全被委托给NioEndpoint实现。tomcat在使用Http11NioProtocol解析HTTP请求时一共设计了三种线程,分别为Acceptor,Poller和Worker。

1、Acceptor线程

Acceptor实现了Runnable接口,根据其命名就知道它是一个接收器,负责接收socket,其接收方法是serverSocket.accept()方式,获得SocketChannel对象,然后封装成tomcat自定义的org.apache.tomcat.util.net.NioChannel。虽然是Nio,但在接收socket时仍然使用传统的方法,使用阻塞方式实现。Acceptor以线程池的方式被创建和管理,在NioEndpoint的startInternal()方法中完成Acceptor的启动,源码如下:

public void startInternal() throws Exception {if (!running) {running = true;paused = false;processorCache = new SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE,socketProperties.getProcessorCache());eventCache = new SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE,socketProperties.getEventCache());nioChannels = new SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE,socketProperties.getBufferPool());// Create worker collectionif ( getExecutor() == null ) {createExecutor();}//设置最大连接数,默认值为maxConnections = 10000,通过同步器AQS实现。
        initializeConnectionLatch();//默认是2个,Math.min(2,Runtime.getRuntime().availableProcessors());和虚拟机处理器个数比较// Start poller threadspollers = new Poller[getPollerThreadCount()];for (int i=0; i<pollers.length; i++) {pollers[i] = new Poller();Thread pollerThread = new Thread(pollers[i], getName() + "-ClientPoller-"+i);pollerThread.setPriority(threadPriority);pollerThread.setDaemon(true);pollerThread.start();}

        startAcceptorThreads();}
}

继续追踪startAcceptorThreads的源码

protected final void startAcceptorThreads() {//启动Acceptor线程,默认是1个int count = getAcceptorThreadCount();acceptors = new Acceptor[count];for (int i = 0; i < count; i++) {acceptors[i] = createAcceptor();String threadName = getName() + "-Acceptor-" + i;acceptors[i].setThreadName(threadName);Thread t = new Thread(acceptors[i], threadName);t.setPriority(getAcceptorThreadPriority());t.setDaemon(getDaemon());t.start();}
}

Acceptor线程的核心代码在它的run方法中:

protected class Acceptor extends AbstractEndpoint.Acceptor {@Overridepublic void run() {int errorDelay = 0;// Loop until we receive a shutdown commandwhile (running) {// Loop if endpoint is pausedwhile (paused && running) {state = AcceptorState.PAUSED;try {Thread.sleep(50);} catch (InterruptedException e) {// Ignore
                }}if (!running) {break;}state = AcceptorState.RUNNING;try {//if we have reached max connections, wait
                countUpOrAwaitConnection();SocketChannel socket = null;try {// Accept the next incoming connection from the server// socket//接收socket请求socket = serverSock.accept();} catch (IOException ioe) {// We didn't get a socket
                    countDownConnection();if (running) {// Introduce delay if necessaryerrorDelay = handleExceptionWithDelay(errorDelay);// re-throwthrow ioe;} else {break;}}// Successful accept, reset the error delayerrorDelay = 0;// Configure the socketif (running && !paused) {// setSocketOptions() will hand the socket off to// an appropriate processor if successfulif (!setSocketOptions(socket)) {closeSocket(socket);}} else {closeSocket(socket);}} catch (Throwable t) {ExceptionUtils.handleThrowable(t);log.error(sm.getString("endpoint.accept.fail"), t);}}state = AcceptorState.ENDED;}private void closeSocket(SocketChannel socket) {countDownConnection();try {socket.socket().close();} catch (IOException ioe)  {if (log.isDebugEnabled()) {log.debug(sm.getString("endpoint.err.close"), ioe);}}try {socket.close();} catch (IOException ioe) {if (log.isDebugEnabled()) {log.debug(sm.getString("endpoint.err.close"), ioe);}}}
}

Acceptor完成了socket请求的接收,然后交给NioEndpoint 进行配置,继续追踪Endpoint的setSocketOptions方法。

protected boolean setSocketOptions(SocketChannel socket) {// Process the connectiontry {//disable blocking, APR style, we are gonna be polling it//设置为非阻塞socket.configureBlocking(false);Socket sock = socket.socket();socketProperties.setProperties(sock);NioChannel channel = nioChannels.pop();if (channel == null) {SocketBufferHandler bufhandler = new SocketBufferHandler(socketProperties.getAppReadBufSize(),socketProperties.getAppWriteBufSize(),socketProperties.getDirectBuffer());if (isSSLEnabled()) {channel = new SecureNioChannel(socket, bufhandler, selectorPool, this);} else {channel = new NioChannel(socket, bufhandler);}} else {channel.setIOChannel(socket);channel.reset();}//轮训pollers数组元素,调用Poller的register方法,完成channel的注册。
        getPoller0().register(channel);} catch (Throwable t) {ExceptionUtils.handleThrowable(t);try {log.error("",t);} catch (Throwable tt) {ExceptionUtils.handleThrowable(tt);}// Tell to close the socketreturn false;}return true;
}

分析setSocketOptions的源码可以知道,该方法的主要功能是利用传入的SocketChannel参数生成SecureNioChannel或者NioChannel,然后注册到Poller线程的selector中,可以进一步了解Java nio的相关知识,对这一块内容有更深的理解。

2、Poller线程

 Poller同样实现了Runnable接口,是NioEndpoint类的内部类。在Endpoint的startInterval方法中创建、配置并启动了Poller线程,见代码清单4。Poller主要职责是不断轮询其selector,检查准备就绪的socket(有数据可读或可写),实现io的多路复用。其构造其中初始化了selector。

public Poller() throws IOException {this.selector = Selector.open();
}

在分析Acceptor的时候,提到了Acceptor接受到一个socket请求后,调用NioEndpoint的setSocketOptions方法(代码清单6),该方法生成了NioChannel后调用Poller的register方法生成PoolorEvent后加入到Eventqueue,register方法的源码如下:

public void register(final NioChannel socket) {socket.setPoller(this);NioSocketWrapper ka = new NioSocketWrapper(socket, NioEndpoint.this);socket.setSocketWrapper(ka);ka.setPoller(this);ka.setReadTimeout(getSocketProperties().getSoTimeout());ka.setWriteTimeout(getSocketProperties().getSoTimeout());ka.setKeepAliveLeft(NioEndpoint.this.getMaxKeepAliveRequests());ka.setSecure(isSSLEnabled());ka.setReadTimeout(getConnectionTimeout());ka.setWriteTimeout(getConnectionTimeout());PollerEvent r = eventCache.pop();ka.interestOps(SelectionKey.OP_READ);//this is what OP_REGISTER turns into.//生成PoolorEvent并加入到Eventqueueif ( r==null) r = new PollerEvent(socket,ka,OP_REGISTER);else r.reset(socket,ka,OP_REGISTER);addEvent(r);
}

Poller的核心代码也在其run方法中:

public void run() {// Loop until destroy() is called// 调用了destroy()方法后终止此循环while (true) {boolean hasEvents = false;try {if (!close) {hasEvents = events();if (wakeupCounter.getAndSet(-1) > 0) {//if we are here, means we have other stuff to do//do a non blocking select//非阻塞的 selectkeyCount = selector.selectNow();} else {//阻塞selector,直到有准备就绪的socketkeyCount = selector.select(selectorTimeout);}wakeupCounter.set(0);}if (close) {//该方法遍历了eventqueue中的所有PollerEvent,然后依次调用PollerEvent的run,将socket注册到selector中。
                events();timeout(0, false);try {selector.close();} catch (IOException ioe) {log.error(sm.getString("endpoint.nio.selectorCloseFail"), ioe);}break;}} catch (Throwable x) {ExceptionUtils.handleThrowable(x);log.error("",x);continue;}//either we timed out or we woke up, process events firstif ( keyCount == 0 ) hasEvents = (hasEvents | events());Iterator<SelectionKey> iterator =keyCount > 0 ? selector.selectedKeys().iterator() : null;// Walk through the collection of ready keys and dispatch// any active event.//遍历就绪的socket事件while (iterator != null && iterator.hasNext()) {SelectionKey sk = iterator.next();NioSocketWrapper attachment = (NioSocketWrapper)sk.attachment();// Attachment may be null if another thread has called// cancelledKey()if (attachment == null) {iterator.remove();} else {iterator.remove();//调用processKey方法对有数据读写的socket进行处理,在分析Worker线程时会分析该方法
                processKey(sk, attachment);}}//while//process timeouts
        timeout(keyCount,hasEvents);}//while
getStopLatch().countDown();
}

run方法中调用了events方法:

public boolean events() {boolean result = false;PollerEvent pe = null;for (int i = 0, size = events.size(); i < size && (pe = events.poll()) != null; i++ ) {result = true;try {//将pollerEvent中的每个socketChannel注册到selector中
            pe.run();pe.reset();if (running && !paused) {//将注册了的pollerEvent加到endPoint.eventCache
                eventCache.push(pe);}} catch ( Throwable x ) {log.error("",x);}}return result;
}

继续跟进PollerEvent的run方法:

public void run() {if (interestOps == OP_REGISTER) {try {//将SocketChannel注册到selector中,注册时间为SelectionKey.OP_READ读事件
            socket.getIOChannel().register(socket.getPoller().getSelector(), SelectionKey.OP_READ, socketWrapper);} catch (Exception x) {log.error(sm.getString("endpoint.nio.registerFail"), x);}} else {final SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector());try {if (key == null) {// The key was cancelled (e.g. due to socket closure)// and removed from the selector while it was being// processed. Count down the connections at this point// since it won't have been counted down when the socket// closed.
                socket.socketWrapper.getEndpoint().countDownConnection();((NioSocketWrapper) socket.socketWrapper).closed = true;} else {final NioSocketWrapper socketWrapper = (NioSocketWrapper) key.attachment();if (socketWrapper != null) {//we are registering the key to start with, reset the fairness counter.int ops = key.interestOps() | interestOps;socketWrapper.interestOps(ops);key.interestOps(ops);} else {socket.getPoller().cancelledKey(key);}}} catch (CancelledKeyException ckx) {try {socket.getPoller().cancelledKey(key);} catch (Exception ignore) {}}}
}

3、Worker线程

Worker线程即SocketProcessor是用来处理Socket请求的。SocketProcessor也同样是Endpoint的内部类。在Poller的run方法中(代码清单8)监听到准备就绪的socket时会调用processKey方法进行处理:

protected void processKey(SelectionKey sk, NioSocketWrapper attachment) {try {if ( close ) {cancelledKey(sk);} else if ( sk.isValid() && attachment != null ) {//有读写事件就绪时if (sk.isReadable() || sk.isWritable() ) {if ( attachment.getSendfileData() != null ) {processSendfile(sk,attachment, false);} else {unreg(sk, attachment, sk.readyOps());boolean closeSocket = false;// Read goes before write// socket可读时,先处理读事件if (sk.isReadable()) {//调用processSocket方法进一步处理if (!processSocket(attachment, SocketEvent.OPEN_READ, true)) {closeSocket = true;}}//写事件if (!closeSocket && sk.isWritable()) {//调用processSocket方法进一步处理if (!processSocket(attachment, SocketEvent.OPEN_WRITE, true)) {closeSocket = true;}}if (closeSocket) {cancelledKey(sk);}}}} else {//invalid key
            cancelledKey(sk);}} catch ( CancelledKeyException ckx ) {cancelledKey(sk);} catch (Throwable t) {ExceptionUtils.handleThrowable(t);log.error("",t);}
}

继续跟踪processSocket方法:

public boolean processSocket(SocketWrapperBase<S> socketWrapper,SocketEvent event, boolean dispatch) {try {if (socketWrapper == null) {return false;}// 尝试循环利用之前回收的SocketProcessor对象,如果没有可回收利用的则创建新的SocketProcessor对象SocketProcessorBase<S> sc = processorCache.pop();if (sc == null) {sc = createSocketProcessor(socketWrapper, event);} else {// 循环利用回收的SocketProcessor对象
            sc.reset(socketWrapper, event);}Executor executor = getExecutor();if (dispatch && executor != null) {//SocketProcessor实现了Runneble接口,可以直接传入execute方法进行处理
            executor.execute(sc);} else {sc.run();}} catch (RejectedExecutionException ree) {getLog().warn(sm.getString("endpoint.executor.fail", socketWrapper) , ree);return false;} catch (Throwable t) {ExceptionUtils.handleThrowable(t);// This means we got an OOM or similar creating a thread, or that// the pool and its queue are fullgetLog().error(sm.getString("endpoint.process.fail"), t);return false;}return true;
}//NioEndpoint中createSocketProcessor创建一个SocketProcessor。
protected SocketProcessorBase<NioChannel> createSocketProcessor(SocketWrapperBase<NioChannel> socketWrapper, SocketEvent event) {return new SocketProcessor(socketWrapper, event);
}

总结:

Http11NioProtocol是基于Java Nio实现的,创建了Acceptor、Poller和Worker线程实现多路io的复用。三类线程之间的关系如下图所示:

Acceptor和Poller之间是生产者消费者模式的关系,Acceptor不断向EventQueue中添加PollerEvent,Pollor轮询检查EventQueue中就绪的PollerEvent,然后发送给Work线程进行处理。

 

转载于:https://www.cnblogs.com/grasp/p/10099897.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/265232.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

AppDelegate

一、基础知识 1) main.m指定了程序的入口点 UIApplicationMain(argc, argv,nil,NSStringFromClass([StartingPointAppDelegateclass])); 2) AppDelegate的入口点 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptio…

计算机应用基础期末考试要点,计算机应用基础期末复习要点.doc

PAGE 4 / NUMPAGES 5 计算机应用基础 期末复习要点 DATE \ "yyyy-M-d" 2009-1-2PAGE计算机应用基础期末复习要点基础世界上第一台电子数字计算机取名为ENIAC。美籍匈牙利数学家冯诺伊曼提出的计算机的基本工作原理是程序存储。根据计算机使用的主要元器件&#xff0c…

快速对比UART、SPI、I2C通信的区别与应用

参考&#xff1a;带你快速对比SPI、UART、I2C通信的区别与应用&#xff01; 作者&#xff1a;一口Linux 网址&#xff1a;https://mp.weixin.qq.com/s/4_RSM2jk2W6nTboO1W8HCw 电子设备之间的通信就像人类之间的交流&#xff0c;双方都需要说相同的语言。在电子产品中&#xff…

Java使用线程并发库模拟弹夹装弹以及发射子弹的过程

同样是从网上看到的一个需求&#xff0c;需求描述都在代码中。 不多说了&#xff0c;直接贴代码了。相信大家都能够看得懂的&#xff01; package cn.yw.bore;import java.util.ArrayList; import java.util.List; import java.util.concurrent.ArrayBlockingQueue; import jav…

计算机结构原理初步教案板书设计,(计算机工作原理)教学设计(教案)

《(计算机工作原理)教学设计(教案)》由会员分享&#xff0c;可在线阅读&#xff0c;更多相关《(计算机工作原理)教学设计(教案)(5页珍藏版)》请在人人文库网上搜索。1、计算机系统的基本组成教学设计基本信息学 科信息技术年 级初二教学形式多媒体教学教 师彭裕红单 位梅州市梅…

U-Boot 移植

目录NXP官方开发板uboot编译测试查找NXP官方的开发板默认配置文件_defconfig配置编译NXP官方开发板对应的uboot烧写验证与驱动测试(定位缺少的驱动)在NXP官方U-Boot 中添加自己的开发板添加开发板默认配置文件添加开发板对应的头文件(mx6ull_alientek_emmc.h)添加开发板对应的板…

江苏计算机信息录入技师选拔考试题,2010年江苏省机关事业单位工人技师资格选拔考试试卷...

考题2010年江苏省机关事业单位工人技师资格选拔考试试卷计算机一、单项选择题1.计算机之所以能按人们的意志自动进行工作&#xff0c;最直接的原因是因为采用()A&#xff0e;二进制数制 B.高速电子元件 C.存储程序控制 D.程序设计语言2.十进制数269转换为十六进制数为()A&#…

打印某个进程下的所有线程--Linux环境

2019独角兽企业重金招聘Python工程师标准>>> 1、ps -mp <进程ID> -o THREAD 在当前用户下&#xff0c;列出pid包含的所有线程。 2、ps -mp <进程ID> -o THREAD,tid 在当前用户下&#xff0c;列出pid包含的所有线程信息及本地线程ID (tid)。 3、ps -…

JavaScript笔记(3)

•位操作符 所有的按位操作符的操作数都会被转成补码形式的有符号的32位整数。 运算符用法描述按位与&#xff08;AND&#xff09;a & b对于每一个比特位&#xff0c;只有两个操作数相应的比特位都是1时&#xff0c;结果才为1&#xff0c;否则为0。按位或&#xff08;OR&am…

转 常见hash算法的原理

散列表,它是基于快速存取的角度设计的&#xff0c;也是一种典型的“空间换时间”的做法。顾名思义&#xff0c;该数据结构可以理解为一个线性表&#xff0c;但是其中的元素不是紧密排列的&#xff0c;而是可能存在空隙。 散列表&#xff08;Hash table&#xff0c;也叫哈希表&a…

Linux 内核顶层Makefile 详解

目录前602行分析make xxx_defconfig 过程Makefile.build 脚本分析make 过程built-in.o 文件编译生成过程make zImage 过程前几章我们重点讲解了如何移植uboot 到I.MX6U-ALPHA 开发板上&#xff0c;从本章开始我们就开始学习如何移植Linux 内核。同uboot 一样&#xff0c;在具体…

android第三次作业

界面&#xff1a; 主要代码&#xff1a; 1.定义一个工具类&#xff0c;在这个类中获取音频文件&#xff0c;并且对歌曲名、歌手和时间等进行格式规范&#xff1a; package com.example.administrator.music;import android.content.Context; import android.database.Cursor; i…

2013年国家计算机一级考试试题,2013年计算机一级的考试试题.doc

2013年计算机一级的考试试题.doc2013年计算机一级考试试题一、单项选择题1、 把计算机分巨型机、大中型机、小型机和微型机&#xff0c;本质上是按_____划分。A 计算机的体积 B CPU的集成度C 计算机总体规模和运算速度 D 计算机的存储容量2、 以微处理器为核心组成的微型计算机…

python try 异常处理 史上最全

在程序出现bug时一般不会将错误信息显示给用户&#xff0c;而是现实一个提示的页面&#xff0c;通俗来说就是不让用户看见大黄页&#xff01;&#xff01;&#xff01; 有时候我们写程序的时候&#xff0c;会出现一些错误或异常&#xff0c;导致程序终止. 为了处理异常&#xf…

Spring+Spring Security+JSTL实现的表单登陆的例子

2019独角兽企业重金招聘Python工程师标准>>> Spring Security允许开发人员轻松地将安全功能集成到J2EE Web应用程序中&#xff0c;它通过Servlet过滤器实现“用户自定义”安全检查。 在本教程中&#xff0c;我们将向您展示如何在Spring MVC中集成Spring Security 3…

数学教师计算机能力提升,深度融合信息技术,提升数学课堂魅力

原标题&#xff1a;深度融合信息技术&#xff0c;提升数学课堂魅力2018年小学数学教学与信息技术深度融合专题网络教研活动2018年10月31日&#xff0c;我校数学科组根据北片指导中心文件精神&#xff0c;进行了一次小学数学教学与信息技术深度融合专题网络教研活动。本次教研活…

Linux 内核启动流程

目录链接脚本vmlinux.ldsLinux 内核入口stext__mmap_switched 函数start_kernel 函数rest_init 函数init 进程看完Linux 内核的顶层Makefile 以后再来看Linux 内核的大致启动流程&#xff0c;Linux 内核的启动流程要比uboot 复杂的多&#xff0c;涉及到的内容也更多&#xff0c…

vs文件上传失败--超过最大字符限制

一、问题 在文件上传时&#xff0c;会遇到大文件上传失败。 》F12查看报错网络请求返回结果 》问题分析 由于vs上传文件默认的字符大小控制。 二、解决方法 》在web.config中修改或添加最大允许上传文件的大小 1 <system.web> 2 <httpRuntime targetFramework&q…

为什么linux默认都没有MP3和视频或者连FLASH都没有呢?

为什么linux默认都没有MP3和视频或者连FLASH都没有呢&#xff1f;这是转自官方的说明。先后明&#xff0c;后面讲一下如何动手来让LINUX支持这些最基本的功能&#xff01;为什么 Fedora 没有包含对专有格式例如 MP3 或 MPEG 的支持&#xff1f; MP3 和 MPEG 格式受专利保护&…

微计算机和微处理器的区别,CPU和微处理器的区别

CPU和微处理器是成功操作系统的基础。它们都执行不可或缺的计算机任务&#xff0c;例如算术&#xff0c;数据处理&#xff0c;逻辑和I / O操作&#xff0c;但是CPU与微处理器的区别并不是那么黑与白。尽管一些IT管理员可以互换使用CPU和微处理器&#xff0c;但现实是大多数CPU是…