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

聊城网站建设基本流程重庆seo网站运营

聊城网站建设基本流程,重庆seo网站运营,网站规划与网页设计,哈尔滨市哪里做淘宝网站2024年10月14日14:17:07—0.6.0 java-实现一个简单的httpserver-0.6.0 背景功能具体代码打印 背景 通常写了一些接口,需要通过临时的http访问,又不需要spring这么厚重的框架 功能 设置并发监控并发两个get请求一个是根路径,一个是other增加…

2024年10月14日14:17:07—0.6.0

java-实现一个简单的httpserver-0.6.0

    • 背景
    • 功能
    • 具体代码
    • 打印

背景

通常写了一些接口,需要通过临时的http访问,又不需要spring这么厚重的框架

功能

  1. 设置并发
  2. 监控并发
  3. 两个get请求一个是根路径,一个是other
  4. 增加了一个post请求的方法other1

具体代码

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;public class server {private static AtomicInteger concurrentConnections = new AtomicInteger(0);public static void main(String[] args) throws IOException {HttpServer server = HttpServer.create(new InetSocketAddress("localhost", 8222), 0);// 处理根路径get请求server.createContext("/", new RootHandler());// 处理 /other 路径get请求server.createContext("/other", new OtherHandler());// 处理 /other1 路径post请求server.createContext("/other1", new Other1Handler());// 设置并发连接数server.setExecutor(java.util.concurrent.Executors.newFixedThreadPool(10));server.start();System.out.println("Server started on port 8000.");// 定期打印当前并发连接数new Thread(() -> {while (true) {try {Thread.sleep(5000);System.out.println("Current concurrent connections: " + concurrentConnections.get());} catch (InterruptedException e) {Thread.currentThread().interrupt();}}}).start();}static class RootHandler implements HttpHandler {@Overridepublic void handle(HttpExchange exchange) throws IOException {concurrentConnections.incrementAndGet();if ("GET".equals(exchange.getRequestMethod())) {String response = "Hello from root path!";exchange.sendResponseHeaders(200, response.length());OutputStream os = exchange.getResponseBody();os.write(response.getBytes());os.close();// 监控连接释放事件System.out.println("root Connection released");}concurrentConnections.decrementAndGet();}}static class OtherHandler implements HttpHandler {@Overridepublic void handle(HttpExchange exchange) throws IOException {concurrentConnections.incrementAndGet();if ("GET".equals(exchange.getRequestMethod())) {String response = "This is a response for /other path.";exchange.sendResponseHeaders(200, response.length());OutputStream os = exchange.getResponseBody();os.write(response.getBytes());os.close();}// 监控连接释放事件System.out.println("/other Connection released");concurrentConnections.decrementAndGet();}}static class Other1Handler implements HttpHandler {@Overridepublic void handle(HttpExchange exchange) throws IOException {concurrentConnections.incrementAndGet();if ("POST".equals(exchange.getRequestMethod())) {String response = "This is a response for /other1 post path.";exchange.sendResponseHeaders(200, response.length());OutputStream os = exchange.getResponseBody();os.write(response.getBytes());os.close();}// 监控连接释放事件System.out.println("/other Connection released");concurrentConnections.decrementAndGet();}}
}

打印

root Connection released
Current concurrent connections: 0
/other Connection released
root Connection released
/other Connection released
/other Connection released
/other Connection released
/other Connection released
/other Connection released
Current concurrent connections: 0
/other Connection released
/other Connection released
/other Connection released
root Connection released
Current concurrent connections: 0
Current concurrent connections: 0
http://www.hkea.cn/news/577/

相关文章:

  • h5〃wordpress优化师是一份怎样的工作
  • 漯河市城市建设投资公司网站软文推广文章范文1000
  • 淘宝网页长春网站seo公司
  • 网站服务器一个多少钱免费文件外链网站
  • 网站 什么语言开发的网站加速
  • 负责网站开发的岗位站长工具seo查询软件
  • 自己做网站能赚钱吗企业推广文案
  • 网站怎么容易被百度收录链接买卖
  • 做网站公司青岛磁力猫引擎入口
  • 商业计划书ppt模板免费下载网站seo诊断分析报告
  • 做ppt的网站叫什么怎么做百度网页
  • 觉 网站seo是一种利用搜索引擎的
  • 手机app软件怎么开发合肥seo管理
  • 网页制作教程免费下载国内做seo最好的公司
  • 个人网站制作模板响应式广州新闻24小时爆料热线
  • 宁波网站建设在线单页网站seo如何优化
  • 表格网站怎么做八种营销模式
  • 开发网站公司如何运营怎么让关键词快速排名首页
  • wordpress顶部颜色改哪网站关键词百度自然排名优化
  • 网站开发技术汇总北京seo全网营销
  • 小程序推广任务入口如何做网站搜索引擎优化
  • 国内空间没备案可以打开网站吗最新黑帽seo培训
  • 甘肃公司网站建设哪家好陕西疫情最新消息
  • 潍坊网站建设团队google免登录网页版
  • 无锡企业建设网站公司环球军事网
  • 网站建设的建议网站优化推广方法
  • 怎么做html5网站吗sem优化服务公司
  • 淘宝客网站开发平台网络外包运营公司
  • SEO网站公司小程序开发教程全集免费
  • 贵州网站建设联系电话百度一下百度一下你知道