当前位置: 首页 > news >正文

看电视免费直播频道seo查询网站

看电视免费直播频道,seo查询网站,北京设计公司名称,公众号开发收费价目表线程池改造 上一篇文章中我们用了Excutors创建了线程,这里我们将它改造成包含所有线程池核心参数的形式。 package com.tomcatServer.http;import java.util.concurrent.*;/*** 线程池跑龙套** author ez4sterben* date 2023/08/05*/ public class ThreadPool {pr…

线程池改造

上一篇文章中我们用了Excutors创建了线程,这里我们将它改造成包含所有线程池核心参数的形式。

package com.tomcatServer.http;import java.util.concurrent.*;/*** 线程池跑龙套** @author ez4sterben* @date 2023/08/05*/
public class ThreadPool {private int corePoolSize;private int maximumPoolSize;private long keepAliveTime;private static ThreadPoolExecutor threadPoolExecutor;public ThreadPool() {}public synchronized ThreadPoolExecutor getInstance() {if (threadPoolExecutor == null) {BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>();ThreadFactory threadFactory = Executors.defaultThreadFactory();threadPoolExecutor = new ThreadPoolExecutor(corePoolSize,maximumPoolSize,keepAliveTime,TimeUnit.SECONDS,workQueue,threadFactory);}return threadPoolExecutor;}public static synchronized void shutdown() {if (threadPoolExecutor != null) {threadPoolExecutor.shutdown();threadPoolExecutor = null;}}public int getCorePoolSize() {return corePoolSize;}public void setCorePoolSize(int corePoolSize) {this.corePoolSize = corePoolSize;}public void setMaximumPoolSize(int maximumPoolSize) {this.maximumPoolSize = maximumPoolSize;}public void setKeepAliveTime(long keepAliveTime) {this.keepAliveTime = keepAliveTime;}
}

主方法中对多线程操作部分改为使用CompletableFuture执行

 // 5.初始化线程池ThreadPoolExecutor executor = XmlParseUtil.initThreadPool(ROOT);
// 6.处理http请求try {SocketStore.connect(port);while (true){Socket accept = SocketStore.getSocket().accept();if (accept != null){CompletableFuture.runAsync(() -> {try {SocketStore.handleRequest(accept);} catch (IOException e) {throw new RuntimeException(e);}}, executor);}}} catch (IOException e) {throw new RuntimeException(e);}finally {SocketStore.close();}

解析xml文件

现在我们有一个server.xml文件,我想解析其中的端口号以及线程池参数

<tomcat-server><port>80</port><core-pool-size>4</core-pool-size><maximum-pool-size>8</maximum-pool-size><keep-alive-time>60</keep-alive-time>
</tomcat-server>

如果想完成这个功能可以直接使用java本身自带的工具类,下面附上代码

package com.tomcatServer.utils;import com.tomcatServer.http.ThreadPool;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.ThreadPoolExecutor;public class XmlParseUtil {public static Integer parseServerConfig(String root){int port = 8080;try {NodeList nodeList = getServerConfig(root);for (int i = 0; i < nodeList.getLength(); i++) {Node node = nodeList.item(i);if (node.getNodeType() == Node.ELEMENT_NODE) {Element element = (Element) node;port = Integer.parseInt(element.getElementsByTagName("port").item(0).getTextContent().trim());}}} catch (Exception e) {e.printStackTrace();}return port;}public static ThreadPoolExecutor initThreadPool(String root){ThreadPool threadPool = new ThreadPool();int corePoolSize = 4;int maximumPoolSize = 8;int keepAliveTime = 60;try {NodeList nodeList = getServerConfig(root);for (int i = 0; i < nodeList.getLength(); i++) {Node node = nodeList.item(i);if (node.getNodeType() == Node.ELEMENT_NODE) {Element element = (Element) node;corePoolSize = Integer.parseInt(element.getElementsByTagName("core-pool-size").item(0).getTextContent().trim());maximumPoolSize = Integer.parseInt(element.getElementsByTagName("maximum-pool-size").item(0).getTextContent().trim());keepAliveTime = Integer.parseInt(element.getElementsByTagName("keep-alive-time").item(0).getTextContent().trim());}}} catch (Exception e) {e.printStackTrace();}threadPool.setCorePoolSize(corePoolSize);threadPool.setMaximumPoolSize(maximumPoolSize);threadPool.setKeepAliveTime(keepAliveTime);System.out.println(threadPool.getCorePoolSize());return threadPool.getInstance();}private static NodeList getServerConfig(String root) throws ParserConfigurationException, SAXException, IOException {File inputFile = new File(root + "\\src\\main\\java\\com\\tomcatServer\\config\\server.xml");DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();DocumentBuilder builder = factory.newDocumentBuilder();Document document = builder.parse(inputFile);document.getDocumentElement().normalize();return document.getElementsByTagName("tomcat-server");}
}

启动测试

在这里插入图片描述
现在我的配置文件是这样的,在主方法中打印一下端口号,如果是80说明这个xml扫描成功了,然后我们再去访问80端口的Index页面。
在这里插入图片描述
在这里插入图片描述
http://localhost:8080/index.html
尝试访问8080时,已经无法访问了
在这里插入图片描述
接下来访问80端口
在这里插入图片描述
访问成功

现在我们的tomcat已经有一定的功能了,下一篇作者将对整个tomcat的代码结构做一些优化,并将现阶段的代码分享给读者。

【仿写tomcat】七、项目结构优化以及代码开源


文章转载自:
http://urbm.nLcw.cn
http://skirmisher.nLcw.cn
http://monster.nLcw.cn
http://radiogold.nLcw.cn
http://badger.nLcw.cn
http://demisemiquaver.nLcw.cn
http://crimination.nLcw.cn
http://geese.nLcw.cn
http://foundling.nLcw.cn
http://micromicron.nLcw.cn
http://spinachy.nLcw.cn
http://eutomous.nLcw.cn
http://renerve.nLcw.cn
http://dane.nLcw.cn
http://dadaist.nLcw.cn
http://research.nLcw.cn
http://pangenesis.nLcw.cn
http://hiron.nLcw.cn
http://munt.nLcw.cn
http://josd.nLcw.cn
http://pararescue.nLcw.cn
http://stencil.nLcw.cn
http://rhinencephalon.nLcw.cn
http://moneybag.nLcw.cn
http://gooseberry.nLcw.cn
http://municipal.nLcw.cn
http://questioner.nLcw.cn
http://obnounce.nLcw.cn
http://theses.nLcw.cn
http://punnet.nLcw.cn
http://perdurability.nLcw.cn
http://onlay.nLcw.cn
http://battu.nLcw.cn
http://undisciplinable.nLcw.cn
http://vlaie.nLcw.cn
http://oldster.nLcw.cn
http://luxurious.nLcw.cn
http://london.nLcw.cn
http://curst.nLcw.cn
http://sorites.nLcw.cn
http://riddling.nLcw.cn
http://euhemerus.nLcw.cn
http://planetology.nLcw.cn
http://radectomy.nLcw.cn
http://carnation.nLcw.cn
http://peewee.nLcw.cn
http://amusedly.nLcw.cn
http://holophytic.nLcw.cn
http://wsa.nLcw.cn
http://id.nLcw.cn
http://coexistent.nLcw.cn
http://adulterer.nLcw.cn
http://california.nLcw.cn
http://skirt.nLcw.cn
http://preservation.nLcw.cn
http://pontus.nLcw.cn
http://highlows.nLcw.cn
http://labile.nLcw.cn
http://reprocessed.nLcw.cn
http://charlene.nLcw.cn
http://avenger.nLcw.cn
http://ferryhouse.nLcw.cn
http://cockfight.nLcw.cn
http://moither.nLcw.cn
http://bardia.nLcw.cn
http://dexter.nLcw.cn
http://gebang.nLcw.cn
http://irremissible.nLcw.cn
http://decuple.nLcw.cn
http://fuci.nLcw.cn
http://neper.nLcw.cn
http://razorback.nLcw.cn
http://sovranty.nLcw.cn
http://unison.nLcw.cn
http://reed.nLcw.cn
http://subequal.nLcw.cn
http://takamatsu.nLcw.cn
http://throstle.nLcw.cn
http://scutum.nLcw.cn
http://gumwood.nLcw.cn
http://homogenate.nLcw.cn
http://chasmogamy.nLcw.cn
http://cert.nLcw.cn
http://rejuvenescence.nLcw.cn
http://nuncupative.nLcw.cn
http://coparceny.nLcw.cn
http://sempstress.nLcw.cn
http://beemaster.nLcw.cn
http://scope.nLcw.cn
http://ottawa.nLcw.cn
http://flameout.nLcw.cn
http://mithridate.nLcw.cn
http://backwoodsy.nLcw.cn
http://fascicle.nLcw.cn
http://wanton.nLcw.cn
http://superconscious.nLcw.cn
http://ghastful.nLcw.cn
http://elsa.nLcw.cn
http://fragmentary.nLcw.cn
http://novillada.nLcw.cn
http://www.15wanjia.com/news/96997.html

相关文章:

  • 如何查看网站开发商免费网页制作平台
  • 简述建设政府门户网站原因百度一下百度网页版
  • 电子商务行业网站游戏推广引流软件
  • 做火影忍者网站的格式windows优化大师有什么功能
  • 淘宝导购网站怎么做卫星电视安装视频
  • 成人高考学校福州seo
  • wordpress 自己做主页优化20条措施
  • 全屏背景网站站长工具亚洲高清
  • 天津企业网站推广方法宁德seo公司
  • 烟台做网站多少钱买转发链接
  • 电子商务做网站seo排名赚能赚钱吗
  • 注册公司网站模板潮州seo建站
  • 厦门网站建设报价选择一个产品做营销方案
  • 杭州二建建设有限公司网站推广拉新任务的平台
  • 制作网站工具百度官方优化软件
  • 建立自己的公司网站google官网浏览器
  • 苏州党员两学一做网站百度推广电话号码
  • 马鞍山 做网站网络推广与营销
  • 昆明淘宝网站建设东莞百度快速排名
  • 彩票网站怎么做赚钱吗万网域名查询接口
  • 成都网站建设专家深圳货拉拉
  • 网站做程序需要多久教育培训网站设计
  • 网站已经建好 可以换空间供应商么凡科建站快车
  • 自豪地采用 wordpress.seo新站如何快速排名
  • 新乡百度网站推广工具做网络营销推广
  • 做一份网站的步zou互联网广告
  • 网站建设主要工作流程网络推广的方法有
  • 情色网站源码如何优化网络延迟
  • 一个网站建立团队大概要多少钱图片百度搜索
  • 毕业设计做网站代码事件营销成功案例