IO/NIO交互模拟及渐进式实现

IO

IO Server

public class SocketServer {public static void main(String[] args)  {//server编号和client编号对应,优缺点注释在server端//server1();//server2();server3();}/*** server1的缺点:* 1、accept()方法阻塞了线程,要等客户端连接后才能继续处理(一个客户端连接,对应一个服务端处理线程)* 2、当客户端与服务端完成一次交互后,程序就结束了* 3、流关闭代码比较臃肿、BufferedWriter的内容需要在末尾加'\n'* 4、交互的内容写死,不可以通过控制台输入* 5、端口号固定、ip固定、readLine读取一行等等*/public static void server1() {ServerSocket serverSocket = null;BufferedReader bufferedReader = null;BufferedWriter bufferedWriter = null;try {serverSocket = new ServerSocket(8999);//阻塞至客户端连接成功Socket socket = serverSocket.accept();bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));//readLine会阻塞String s = bufferedReader.readLine();System.out.println("服务端接收到客户端的消息:" + s);bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));bufferedWriter.write("服务端发送消息给客户端\n");bufferedWriter.flush();} catch (IOException e) {throw new RuntimeException(e);} finally {//各个try catch 必须分开写,聚合成一个会导致一个流关闭异常,无法进入其他流的关闭流程if(serverSocket != null) {try {serverSocket.close();} catch (IOException e) {throw new RuntimeException(e);}}if(bufferedWriter != null) {try {bufferedWriter.close();} catch (IOException e) {throw new RuntimeException(e);}}//只需要关闭外层的缓冲区,其close方法内部关闭了了传入的流//如果不关闭,只是等待jvm兜底finally,会在不确定的时间内对资源造成占用(如果是文件读写会对文件描述符fd的占用)if (bufferedReader != null) {try {bufferedReader.close();} catch (IOException e) {throw new RuntimeException(e);}}}}/*** server2优点:* 1、服务端和客户端可以任意次交互,可以连续发送消息* 2、优化了流关闭的写法** server2的缺点:* 1、accept()方法阻塞了线程,要等客户端连接后才能继续处理(一个客户端连接,对应一个服务端处理线程)* 2、cpu空转* 3、ip固定等等* 4、一个服务端只能和一个客户端交互*/public static void server2() {System.out.println("请输入端口号,并等待客户端连接...");try (BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));ServerSocket serverSocket = new ServerSocket(Integer.valueOf(consoleReader.readLine()));Socket socket = serverSocket.accept();BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));){System.out.println("客户端已连接,开始和客户端交互...");//这个循环保证可以连续发送或者接收多条消息while (true) {if (bufferedReader.ready()) {System.out.println("收到客户端的消息:" + bufferedReader.readLine());}if (consoleReader.ready()) {printWriter.println(consoleReader.readLine());printWriter.flush();}}//只能发一次接收一次
//            while (true) {
//                System.out.println("收到客户端的消息:" + bufferedReader.readLine());
//
//                printWriter.println(consoleReader.readLine());
//                printWriter.flush();
//            }} catch (IOException e) {throw new RuntimeException(e);}}/*** server3优点:* 一个服务端可以和一个客户端交互* 加上了线程池** server3的缺点:* 1、accept()方法阻塞了线程,要等客户端连接后才能继续处理(一个客户端连接,对应一个服务端处理线程)* 2、cpu空转* 3、ip固定等等* 4、如果开启多个客户端,因System.in被服务端共享,所以服务端发送消息后,客户端会随机接收其中个别消息*/public static void server3() {ThreadPoolExecutor pool = new ThreadPoolExecutor(0, Runtime.getRuntime().availableProcessors() * 2,60L, TimeUnit.SECONDS,new SynchronousQueue<Runnable>());System.out.println("请输入端口号,并等待客户端连接...");try (BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));ServerSocket serverSocket = new ServerSocket(Integer.valueOf(consoleReader.readLine()));){//这个循环保证多个客户端连接while (true) {Thread.sleep(1000);Socket socket = serverSocket.accept();System.out.println("客户端已连接,开始和客户端交互...");pool.submit(new Thread(()->{try(BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));) {while (true) {Thread.sleep(1000);if(bufferedReader.ready()) {System.out.println("收到客户端"+ Thread.currentThread() +"的消息:" + bufferedReader.readLine());}if (consoleReader.ready()) {printWriter.println(consoleReader.readLine());printWriter.flush();}}} catch (IOException e) {throw new RuntimeException(e);} catch (InterruptedException e) {throw new RuntimeException(e);} finally {if(socket != null) {try {socket.close();} catch (IOException e) {throw new RuntimeException(e);}}}}));}} catch (IOException e) {throw new RuntimeException(e);} catch (InterruptedException e) {throw new RuntimeException(e);}}
}

IO Client

public class SocketClient {public static void main(String[] args) {//client1();//client2();client3();}public static void client1() {Socket socket = null;BufferedReader bufferedReader = null;BufferedWriter bufferedWriter = null;try {socket = new Socket("127.0.0.1", 8999);bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));//换行符必不可少,不然服务端readLine()无法判断一行已经写完bufferedWriter.write("客户端发送消息给服务端\n");bufferedWriter.flush();bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));String s = bufferedReader.readLine();System.out.println("客户端接收到服务端的消息:" + s);} catch (IOException e) {throw new RuntimeException(e);} finally {if(socket != null) {try {socket.close();} catch (IOException e) {throw new RuntimeException(e);}}if(bufferedWriter != null) {try {bufferedWriter.close();} catch (IOException e) {throw new RuntimeException(e);}}if (bufferedReader != null) {try {bufferedReader.close();} catch (IOException e) {throw new RuntimeException(e);}}}}public static void client2() {System.out.println("请输入端口号:");try (BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));Socket socket = new Socket("127.0.0.1", Integer.valueOf(consoleReader.readLine()));PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));){System.out.println("连接成功,开始和服务端交互");//可以连续发送或者接收多条消息while (true) {Thread.sleep(1000);if (bufferedReader.ready()) {System.out.println("收到服务端的消息:" + bufferedReader.readLine());}if (consoleReader.ready()) {printWriter.println(consoleReader.readLine());printWriter.flush();}}//只能发一次接收一次
//            while (true) {
//                printWriter.println(consoleReader.readLine());
//                printWriter.flush();
//
//                System.out.println("收到服务端的消息:" + bufferedReader.readLine());
//            }} catch (IOException e) {throw new RuntimeException(e);} catch (InterruptedException e) {throw new RuntimeException(e);}}public static void client3() {System.out.println("请输入端口号:");try (BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));Socket socket = new Socket("127.0.0.1", Integer.valueOf(consoleReader.readLine()));PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));){System.out.println("连接成功,开始和服务端交互");//可以连续发送或者接收多条消息while (true) {if (bufferedReader.ready()) {System.out.println("收到服务端的消息:" + bufferedReader.readLine());}if (consoleReader.ready()) {printWriter.println(consoleReader.readLine());printWriter.flush();}}} catch (IOException e) {throw new RuntimeException(e);}}
}

NIO

NIO Server

public class SocketServer {public static void main(String[] args) {//server1();//server2();//server3();//server4();server5();}/*** 优点:NIO非阻塞方式,连接不会阻塞、读写不会阻塞* 缺点:* 1、当客户端与服务端完成一次交互后,程序就结束了* 2、交互的内容写死,不可以通过控制台输入* 3、cpu空转* 4、未使用selector多路复用器,其编程其实还是类似与BIO形式(服务端还是每个线程对应一个客户端)*/private static void server1() {try (ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();){serverSocketChannel.socket().bind(new InetSocketAddress(9999));serverSocketChannel.configureBlocking(false);//accept设置了非阻塞,因此需要放置在循环中使用,否则程序直接结束了while (true) {Thread.sleep(1000);SocketChannel socketChannel = serverSocketChannel.accept();if(socketChannel != null) {System.out.println("客户端已连接,开始和客户端交互...");socketChannel.configureBlocking(false);ByteBuffer readBuffer = ByteBuffer.allocate(1024);socketChannel.read(readBuffer);readBuffer.clear();System.out.println("接收到客户端消息: " + new String(readBuffer.array(), "utf-8").trim());ByteBuffer writeBuffer = ByteBuffer.wrap("发送消息给客户端".getBytes());socketChannel.write(writeBuffer);}}} catch (IOException e) {throw new RuntimeException(e);} catch (InterruptedException e) {throw new RuntimeException(e);}}/*** 改良:* 1、支持客户端和服务端一对一交互,多发* 缺点:* 1、不支持一个客户端对多个服务端* 2、如果开启多个客户端,因System.in被服务端共享,所以服务端发送消息后,客户端会随机接收其中个别消息* 3、cpu空转* 4、未使用selector多路复用器,其编程其实还是类似与BIO形式(服务端还是每个线程对应一个客户端)*/private static void server2() {try (ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));){serverSocketChannel.socket().bind(new InetSocketAddress(9999));serverSocketChannel.configureBlocking(false);//accept设置了非阻塞,因此需要放置在循环中使用,否则程序直接结束了while (true) {Thread.sleep(1000);SocketChannel socketChannel = serverSocketChannel.accept();if(socketChannel != null) {System.out.println("客户端已连接,开始和客户端交互...");socketChannel.configureBlocking(false);ByteBuffer readBuffer = ByteBuffer.allocate(1024);while (true) {if(socketChannel.read(readBuffer) > 0) {System.out.println("接收到客户端消息: " + new String(readBuffer.array(), "utf-8").trim());readBuffer.clear();}if (consoleReader.ready()) {ByteBuffer writeBuffer = ByteBuffer.wrap(consoleReader.readLine().getBytes());socketChannel.write(writeBuffer);writeBuffer.clear();}Thread.sleep(1000);}}}} catch (IOException e) {throw new RuntimeException(e);} catch (InterruptedException e) {throw new RuntimeException(e);}}/*** 改良:* 1、支持一个客户端对多个服务端* 缺点:* 1、cpu空转* 2、未使用selector多路复用器,其编程其实还是类似与BIO形式(服务端还是每个线程对应一个客户端)*/private static void server3() {try (ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));) {serverSocketChannel.socket().bind(new InetSocketAddress(9999));serverSocketChannel.configureBlocking(false);List<SocketChannel> socketChannels = new ArrayList<>();//accept设置了非阻塞,因此需要放置在循环中使用,否则程序直接结束了while (true) {Thread.sleep(1000);boolean ready = consoleReader.ready();byte[] bytes = null;if (ready) {bytes = consoleReader.readLine().getBytes();}//调用一次accept再次使用会变成成null,除非有新的客户端连接SocketChannel socketChannel = serverSocketChannel.accept();if (socketChannel != null) {socketChannels.add(socketChannel);socketChannel.configureBlocking(false);System.out.println("客户端已连接,开始和客户端交互...");}for (SocketChannel channel : socketChannels) {ByteBuffer readBuffer = ByteBuffer.allocate(1024);if (channel.read(readBuffer) > 0) {System.out.println("接收到客户端消息: " + new String(readBuffer.array(), "utf-8").trim());readBuffer.clear();}if (ready) {ByteBuffer writeBuffer = ByteBuffer.wrap(bytes);channel.write(writeBuffer);writeBuffer.clear();}}}} catch (IOException e) {throw new RuntimeException(e);} catch (InterruptedException e) {throw new RuntimeException(e);}}/*** 改良:* 1、支持一个客户端对多个服务端 (服务端发送消息,客户端都能收到,所有客户端发送消息服务端都能收到)* 2、相对与server3多线程方式,服务端只需要启动一个主线程即可与所有客户端交互,* 缺点:* 1、cpu空转* 2、未使用selector多路复用器,其编程其实还是类似与BIO形式(服务端还是每个线程对应一个客户端)*/static final List<SocketChannel> socketChannels4 = new CopyOnWriteArrayList<>();private static void server4() {try (ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));) {serverSocketChannel.socket().bind(new InetSocketAddress(9999));serverSocketChannel.configureBlocking(false);//accept设置了非阻塞,因此需要放置在循环中使用,否则程序直接结束了while (true) {SocketChannel socketChannel = serverSocketChannel.accept();if (socketChannel != null) {System.out.println("客户端已连接,开始和客户端交互...");socketChannel.configureBlocking(false);socketChannels4.add(socketChannel);}Iterator<SocketChannel> iterator = socketChannels4.iterator();boolean ready = consoleReader.ready();byte[] writeBytes = null;if (ready) {writeBytes = consoleReader.readLine().getBytes();}while (iterator.hasNext()) {ByteBuffer readBuffer = ByteBuffer.allocate(1024);SocketChannel channel = iterator.next();if (channel.read(readBuffer) > 0) {System.out.println("接收到客户端消息: " + new String(readBuffer.array(), "utf-8").trim());readBuffer.clear();}if (ready) {ByteBuffer writeBuffer = ByteBuffer.wrap(writeBytes);channel.write(writeBuffer);writeBuffer.clear();}}Thread.sleep(1000);}} catch (IOException | InterruptedException e) {throw new RuntimeException(e);}}/*** 改良:* 1、支持一个客户端对多个服务端 (服务端发送消息,客户端都能收到,所有客户端发送消息服务端都能收到)* 2、相对与server3多线程方式,服务端只需要启动一个主线程即可与所有客户端交互,* 缺点:* 1、cpu空转* 2、未使用selector多路复用器,其编程其实还是类似与BIO形式(服务端还是每个线程对应一个客户端)*/private static void server5() {try (ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();Selector selector = Selector.open();BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));) {serverSocketChannel.socket().bind(new InetSocketAddress(9999));serverSocketChannel.configureBlocking(false);//将serverSocketChannel注册到selector, 并监听accept事件serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);List<SocketChannel> socketChannels = new ArrayList<>();while (true) {//非阻塞selector.select(1000);Iterator<SelectionKey> iterator = selector.selectedKeys().iterator();while (iterator.hasNext()) {SelectionKey selectionKey = iterator.next();if(selectionKey.isAcceptable()) {SocketChannel socketChannel = serverSocketChannel.accept();System.out.println("客户端已连接,开始和客户端交互...");socketChannel.configureBlocking(false);socketChannel.register(selector, SelectionKey.OP_READ);socketChannels.add(socketChannel);} else if(selectionKey.isReadable()) {SocketChannel socketChannel = (SocketChannel)selectionKey.channel();ByteBuffer readBuffer = ByteBuffer.allocate(1024);if (socketChannel.read(readBuffer) > 0) {System.out.println("接收到客户端消息: " + new String(readBuffer.array(), "utf-8").trim());readBuffer.clear();}}iterator.remove();}if(consoleReader.ready()) {byte[] bytes = consoleReader.readLine().getBytes();for (SocketChannel socketChannel : socketChannels) {ByteBuffer writeBuffer = ByteBuffer.wrap(bytes);socketChannel.write(writeBuffer);writeBuffer.clear();}}}} catch (IOException e) {throw new RuntimeException(e);}}}

NIO Client

public class SocketClient {public static void main(String[] args) {//client1();//client2_3_4();client5();}private static void client1() {try (SocketChannel socketChannel = SocketChannel.open();){socketChannel.configureBlocking(false);socketChannel.connect(new InetSocketAddress("127.0.0.1", 9999));while (!socketChannel.finishConnect()) {Thread.sleep(1000);System.out.println("正在连接客户端...");}ByteBuffer writeBuffer = ByteBuffer.wrap("向服务端发送消息".getBytes());socketChannel.write(writeBuffer);writeBuffer.clear();ByteBuffer readBuffer = ByteBuffer.allocate(1024);while (true) {if(socketChannel.read(readBuffer) > 0) {System.out.println("接收到服务端消息: " + new String(readBuffer.array(), "utf-8").trim());readBuffer.clear();break;}Thread.sleep(1000);}} catch (IOException | InterruptedException e) {throw new RuntimeException(e);}}private static void client2_3_4() {try (SocketChannel socketChannel = SocketChannel.open();BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));){socketChannel.configureBlocking(false);socketChannel.connect(new InetSocketAddress("127.0.0.1", 9999));while (!socketChannel.finishConnect()) {Thread.sleep(1000);System.out.println("正在连接客户端...");}ByteBuffer readBuffer = ByteBuffer.allocate(1024);while (true) {if(socketChannel.read(readBuffer) > 0) {System.out.println("接收到服务端消息: " + new String(readBuffer.array(), "utf-8").trim());readBuffer.clear();}if (consoleReader.ready()) {ByteBuffer writeBuffer = ByteBuffer.wrap(consoleReader.readLine().getBytes());socketChannel.write(writeBuffer);writeBuffer.clear();}Thread.sleep(1000);}} catch (IOException | InterruptedException e) {throw new RuntimeException(e);}}private static void client5() {try (SocketChannel socketChannel = SocketChannel.open(new InetSocketAddress("127.0.0.1", 9999));Selector selector = Selector.open();BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));){socketChannel.configureBlocking(false);socketChannel.register(selector, SelectionKey.OP_READ);while (true) {selector.select(1000);Iterator<SelectionKey> iterator = selector.selectedKeys().iterator();while (iterator.hasNext()) {SelectionKey selectionKey = iterator.next();if (selectionKey.isReadable()) {SocketChannel channel = (SocketChannel) selectionKey.channel();ByteBuffer readBuffer = ByteBuffer.allocate(1024);if(channel.read(readBuffer) > 0) {System.out.println("接收到服务端消息: " + new String(readBuffer.array(), "utf-8").trim());readBuffer.clear();}}iterator.remove();}if (consoleReader.ready()){ByteBuffer writeBuffer = ByteBuffer.wrap(consoleReader.readLine().getBytes());socketChannel.write(writeBuffer);writeBuffer.clear();}}} catch (IOException e) {throw new RuntimeException(e);}}}

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

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

相关文章

2023年09月青少年软件编程C语言二级真题答案——持续更新.....

数组指定部分逆序重放 将一个数组中的前k项按逆序重新存放。例如,将数组8,6,5,4,1前3项逆序重放得到5,6,8,4,1。 时间限制:1000 内存限制:65536 输入 输入为两行: 第一行两个整数,以空格分隔,分别为数组元素的个数n(1 < n < 100)以及指定的k(1 <= k <= n)。…

【Qt之JSON文件】QJsonDocument、QJsonObject、QJsonArray等类介绍及使用

Qt之JSON相关类介绍 QJsonDocument常用函数枚举类型 QJsonDocument::DataValidation枚举类型 QJsonDocument::JsonFormat构造函数静态函数成员函数示例 QJsonObject常用函数构造函数&#xff1a;成员函数&#xff1a; QJsonObject 与 QVariantMap 相互转换 QJsonArray常用函数构…

无论有没有按钮,iPhone都可以进行截屏操作!如何在iPhone上截屏

通过简单的按键组合&#xff0c;可以很容易地将iPhone屏幕的图片捕获到图像文件中&#xff0c;并保存到照片库中。以下是操作方法。 什么是屏幕截图 屏幕截图是指通常包含你在设备屏幕上看到的内容的精确副本的图像。在设备内拍摄的数字屏幕截图通常使用相机拍摄物理屏幕的照…

AD9371 官方例程HDL详解之JESD204B TX_CLK生成 (二)

AD9371 系列快速入口 AD9371ZCU102 移植到 ZCU106 &#xff1a; AD9371 官方例程构建及单音信号收发 ad9371_tx_jesd -->util_ad9371_xcvr接口映射&#xff1a; AD9371 官方例程之 tx_jesd 与 xcvr接口映射 AD9371 官方例程 时钟间的关系与生成 &#xff1a; AD9371 官方…

HTTPS、SSL/TLS,HTTPS运行过程,RSA加密算法,AES加密算法

1、为什么网站要使用安全证书 我们所处的网络环境是复杂多样的&#xff0c;大致分为两类&#xff0c;一类是可信的网络服务商&#xff0c;比如直接连的电信运营商的网络&#xff0c;网线&#xff0c;4G&#xff0c;5G&#xff1b;另一类是不可信的网络&#xff0c;比如WIFI&am…

Linux笔记之diff工具软件P4merge的使用

Linux笔记之diff工具软件P4merge的使用 code review! 文章目录 Linux笔记之diff工具软件P4merge的使用1.安装和配置2.使用&#xff1a;p4merge a.cc b.cc3.配置git 参考博文: Ubuntu Git可视化比较工具 P4Merge 的安装/配置及使用 1.安装和配置 $ wget https://cdist2.per…

仿CSGO盲盒开箱源码 盲盒商城源码 盲盒开箱源码 潮物盲盒商城源码

仿CSGO盲盒开箱源码 盲盒商城源码 盲盒开箱源码 潮物盲盒商城源码 测试环境&#xff1a;宝塔、Linux、PHP7.2、MySQL5.6 根目录 public&#xff0c;伪静态 thinkphp&#xff0c;php需要Redis扩展 后台&#xff1a;/stf 账号&#xff1a;admin 密码&#xff1a;123123 *后台…

数据结构: map与set的简单实现

目录 map与set的模拟实现 1.基本框架 2.模拟实现map与set所需要做的事 1.使用模板 , 达到泛性编程 2.比较问题 3.迭代器 RBTree中: operator operator-- 4.map [ ] 的实现 5.使用普通迭代器构造const迭代器 效果 map与set的模拟实现 1.基本框架 map set 2.模拟实…

【iOS】MVC模式

MVC&#xff08;Model-View-Controller&#xff0c;模型-视图-控制器&#xff09;模式是相当古老的设计模式之一&#xff0c;ta最早出现在SmallTalk语言中。现在&#xff0c;很多计算机语言和架构都采用了MVC模式。 MVC模式概述 MVC模式是一种设计模式&#xff0c;由3部分组成…

【Spring Cloud】如何确定微服务项目的Spring Boot、Spring Cloud、Spring Cloud Alibaba的版本

文章目录 1. 版本选择2. 用脚手架快速生成微服务的pom.xml3. 创建一个父工程4. 代码地址 本文描述如何确定微服务项目的Spring Boot、Spring Cloud、Spring Cloud Alibaba的版本。 1. 版本选择 我们知道Spring Boot、Spring Cloud、Spring Cloud Alibaba的版本选择一致性非常重…

【ML】cheatsheet

LR 原理与面试题目DT, Adaboost, GBDT, xgboost 原理 细节 与 例子 https://www.cnblogs.com/createMoMo/p/12635709.html xgboost挺详细的算法原理与例子 https://zhuanlan.zhihu.com/p/660468945 着重lightgbm就xgboost的改善方向 https://zhuanlan.zhihu.com/p/366952043机器…

《计算机视觉中的多视图几何》笔记(14)

14 Affine Epipolar Geometry 本章主要是在仿射摄像机的情况下重新考虑对极几何&#xff0c;也就是仿射对极几何。 仿射摄像机的优点是它是线性的&#xff0c;所以很多最优化算法可以用线性代数的知识解决。如果是一般的投影摄像机&#xff0c;很多算法就不是线性的了&#x…

Qt的常用类及作用

Qt是一个跨平台的C应用程序开发框架&#xff0c;提供了丰富的类库和工具&#xff0c;用于创建各种类型的应用程序&#xff0c;包括桌面应用、移动应用、嵌入式应用等。以下是一些Qt中常用的类及其主要作用&#xff1a; 1. QWidget&#xff1a;QWidget是Qt中的基类&#xff0c;…

IDEA 新版本设置菜单展开

使用了新版本的IDEA 新UI后&#xff0c;常用的file&#xff0c;view&#xff0c;菜单看不见了&#xff0c;不太适应&#xff0c;找了一下&#xff0c;有个配置可以修改。 打开settings里面把show main menu in a separate toolbar勾选上&#xff0c;应用保存就可以了

CSS3属性详解(一)文本 盒模型中的 box-ssize 属性 处理兼容性问题:私有前缀 边框 背景属性 渐变 前端开发入门笔记(七)

CSS3是用于为HTML文档添加样式和布局的最新版本的层叠样式表&#xff08;Cascading Style Sheets&#xff09;。下面是一些常用的CSS3属性及其详细解释&#xff1a; border-radius&#xff1a;设置元素的边框圆角的半径。可以使用四个值设置四个不同的圆角半径&#xff0c;也可…

P4 并发控制

文章目录 Task1 锁管理器LockTableUnLockTableLockRowUnLockRow Task2 死锁检测Task3 并发查询执行器Isolation Levelseq_scan_executorinsert_executordelete_executortransaction_manager Task1 锁管理器 LockManager类包含两个属性类&#xff0c;分别是LockRequest和LockRe…

flink中使用GenericWriteAheadSink的优缺点

背景 GenericWriteAheadSink是flink中提供的实现几乎精确一次输出的数据汇抽象类&#xff0c;本文就来看一下使用GenericWriteAheadSink的优缺点 GenericWriteAheadSink的优缺点 先看一下GenericWriteAheadSink的原理图 优点&#xff1a; 几乎可以精确一次的输出&#xf…

漏洞扫描系统的主要功能有哪些

漏洞扫描系统是一种自动化的工具&#xff0c;用于发现和报告计算机网络系统中的安全漏洞。这些漏洞可能包括软件漏洞、配置错误、不安全的网络设备等。漏洞扫描系统的主要功能包括以下几个方面&#xff1a; 目标识别&#xff1a;漏洞扫描系统首先需要识别目标系统的基本信息&am…

在Word中,图片显示不全

在今天交作业的时候&#xff0c;发现了一个非常SB的事情&#xff0c;把图片复制过去显示不完全&#xff1a; 使用文心一言查看搜索了一下&#xff0c;发现可能是以下几种原因&#xff1a; 图片所在行的行高设置不正确。可以重新设置行高&#xff0c;具体步骤包括打开图片显示…

【网络编程】基于epoll的ET模式下的Reactor

需要云服务器等云产品来学习Linux的同学可以移步/-->腾讯云<--/-->阿里云<--/-->华为云<--/官网&#xff0c;轻量型云服务器低至112元/年&#xff0c;新用户首次下单享超低折扣。 目录 一、Reactor介绍 二、基于epoll的ET模式下的Reactor计算器代码 1、Tcp…