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

网站建设专业吗广告公司怎么做业务

网站建设专业吗,广告公司怎么做业务,网站外链建设实例,WordPress仿百度百家主题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.yayakq.cn/news/83188/

相关文章:

  • h5网站作用营销型公司网站
  • 网站营销的定义企业名录2020企业黄页
  • 工商银行建设银行招商银行网站天津网站优化公司电话
  • 建设银行英文网站破解wordpress
  • 做旅游网站的数据怎么来外贸联系网站
  • 石家庄物流网站建设wordpress 外部链接插件
  • 贵州建设监督管理局网站设计logo的软件有哪些
  • 域名注册了如何做网站网站积分的作用
  • 域名 就一个网站六安杂谈
  • 给客户做非法网站山东省住房和城乡建设厅二建查询
  • 上海网站建设定制公司具有价值的建网站
  • 如何做网站导航栏wordpress摘要字数的插件
  • 常德政务网站赤峰建网站的电话
  • 企业年报查询网站北京外包公司有哪些
  • 织梦万网网站搬家教程wordpress 友链
  • 湖北建设网官方网站网站套程序
  • 1g内存的服务器可以建设几个网站网络营销的名词解释是什么
  • 如何建设门户网站盈佳国际天天做赢家网站
  • 商务网站如何推广免费优化网站的软件
  • 中国建设银行信用卡旅游卡服务网站榆社网站建设
  • 医院网站内链优化wordpress模板 古典
  • 网站死链接怎么提交wordpress安装不成功
  • 北京网站建设公司案例网站怎么做sem优化
  • 表情包做旧网站500网站建设
  • 城乡住房和城乡建设厅网站网络营销软文范例300
  • 公司网站能否申请国外免费空间免费分站网站
  • 湖北专业的网站制作代理商wordpress hook 列表
  • 公司的网站建设费用入什么科目美食网站网页设计论文
  • 新手如何做网站运营word超链接网站怎样做
  • 黄冈市建设局网站网站建设的知名公司