{"id":38463,"date":"2025-05-20T16:32:44","date_gmt":"2025-05-20T08:32:44","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/38463.html"},"modified":"2025-05-20T16:32:44","modified_gmt":"2025-05-20T08:32:44","slug":"javafx%e9%a1%b9%e7%9b%ae%e6%80%bb%e7%bb%93-%e7%ae%97%e6%b3%95%e9%a2%98","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/38463.html","title":{"rendered":"JAVAfx\u9879\u76ee\u603b\u7ed3 &amp;&amp; \u7b97\u6cd5\u9898"},"content":{"rendered":"<h2>\u4e00\u3001\u957f\u77ed\u94fe\u63a5<\/h2>\n<h3>1\u3001\u77ed\u8fde\u63a5<\/h3>\n<p>\u5bf9\u4e8e\u77ed\u94fe\u63a5&#xff0c;\u5728\u5199\u5b8c\u8fd9\u4e2a\u9879\u76ee\u7684\u7406\u89e3\u662f\u8fd9\u6837\u7684&#xff0c;\u5bf9\u4e8e\u53d1\u7ed9\u540e\u7aef\u7684\u6bcf\u4e00\u4e2a\u8bf7\u6c42\u90fd\u6709\u4e00\u4e2a\u65b0\u5efasocket&#xff0c;\u5f53\u5b8c\u6210\u524d\u7aef\u548c\u540e\u7aef\u7684\u901a\u4fe1\u6216\u8005\u65ad\u5f00\u65f6\u5373\u53ef\u7ed9\u8fd9\u4e2asocket\u5173\u95ed\u3002\u8fd8\u6709\u5199\u7684\u8fc7\u7a0b\u4e2d\u67e5\u8be2\u8d44\u6599\u5ba4\u77e5\u7684\u4e00\u4e9b\u77e5\u8bc6\u70b9\u3002<\/p>\n<h4>(1)\u77ed\u94fe\u63a5\u7684\u4f18\u70b9<\/h4>\n<p>a.\u5bf9\u4e8e\u670d\u52a1\u5668\u7684\u8d44\u6e90\u5360\u7528\u8f83\u5c11<\/p>\n<p>b.\u76f8\u5bf9\u957f\u8fde\u63a5\u5b9e\u73b0\u8d77\u6765\u76f8\u5bf9\u7b80\u5355<\/p>\n<p>c.\u670d\u52a1\u5668\u4e0d\u9700\u8981\u8bb0\u5f55\u7528\u6237\u7aef\u7684\u72b6\u6001<\/p>\n<h4>(2)\u77ed\u94fe\u63a5\u7684\u7f3a\u70b9<\/h4>\n<p>a.\u4f1a\u9891\u7e41\u7684\u548c\u540e\u7aef\u5efa\u7acb\u94fe\u63a5&#xff0c;\u65ad\u5f00\u8fde\u63a5<\/p>\n<p>b.\u5ef6\u8fdf\u9ad8&#xff0c;\u4e0d\u5229\u4e8e\u5b9e\u65f6\u901a\u4fe1<\/p>\n<p>c.\u4e0d\u9002\u7528\u4e8e\u9ad8\u5e76\u53d1&#xff0c;\u5f88\u6d88\u8017\u540e\u7aef\u7684CPU\u548c\u5185\u5b58<\/p>\n<h4>(3)\u77ed\u94fe\u63a5\u7684\u5e94\u7528\u573a\u666f<\/h4>\n<p>a.\u4f4e\u9891\u8bf7\u6c42<\/p>\n<p>b.\u65e0\u72b6\u6001\u670d\u52a1(\u5305\u62ec\u9759\u6001\u8d44\u6e90\u8bf7\u6c42\u4e0b\u8f7d&#xff0c;\u767b\u5f55\u6ce8\u518c\u5fd8\u8bb0\u5bc6\u7801)<\/p>\n<p>c.\u9ad8\u5b89\u5168\u6027\u8981\u6c42(\u94f6\u884c\u7b49\u4ea4\u6613\u573a\u6240&#xff0c;\u907f\u514d\u4fe1\u606f\u88ab\u76d7\u7a83)<\/p>\n<\/p>\n<p>\u4ee5\u4e0b\u5c31\u662f\u77ed\u94fe\u63a5\u7684\u57fa\u672c\u5b9e\u73b0\u4ee3\u7801<\/p>\n<p>\u7528\u6237\u7aef<\/p>\n<p>import java.io.*;<\/p>\n<p>import java.net.Socket;<\/p>\n<\/p>\n<p>public class ShortConnectionClient {<\/p>\n<p>\u00a0 \u00a0 public static void main(String[] args) {<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 String serverAddress &#061; &#034;localhost&#034;;<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 int port &#061; 8080;<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0\u00a0<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 try {<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u6bcf\u6b21\u8bf7\u6c42\u90fd\u521b\u5efa\u65b0\u7684Socket\u8fde\u63a5<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Socket socket &#061; new Socket(serverAddress, port);<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u83b7\u53d6\u8f93\u51fa\u6d41&#xff0c;\u5411\u670d\u52a1\u5668\u53d1\u9001\u6570\u636e<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 PrintWriter out &#061; new PrintWriter(socket.getOutputStream(), true);<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 out.println(&#034;Hello Server!&#034;);<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u83b7\u53d6\u8f93\u5165\u6d41&#xff0c;\u8bfb\u53d6\u670d\u52a1\u5668\u54cd\u5e94<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 BufferedReader in &#061; new BufferedReader(<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 new InputStreamReader(socket.getInputStream()));<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 String response &#061; in.readLine();<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 System.out.println(&#034;Server response: &#034; &#043; response);<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u5173\u95ed\u8fde\u63a5<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 socket.close();<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 } catch (IOException e) {<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 e.printStackTrace();<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 }<\/p>\n<p>\u00a0 \u00a0 }<\/p>\n<p>}<\/p>\n<p>\u540e\u7aef\u63a5\u6536<\/p>\n<p>import java.io.*; import java.net.ServerSocket; import java.net.Socket;<\/p>\n<p>public class ShortConnectionServer { \u00a0 \u00a0 public static void main(String[] args) { \u00a0 \u00a0 \u00a0 \u00a0 int port &#061; 8080; \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 try (ServerSocket serverSocket &#061; new ServerSocket(port)) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 System.out.println(&#034;Server started on port &#034; &#043; port); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 while (true) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u63a5\u53d7\u5ba2\u6237\u7aef\u8fde\u63a5&#xff08;\u6bcf\u6b21\u90fd\u662f\u65b0\u7684\u8fde\u63a5&#xff09; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Socket clientSocket &#061; serverSocket.accept(); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 System.out.println(&#034;Client connected: &#034; &#043; clientSocket.getInetAddress()); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u5904\u7406\u5ba2\u6237\u7aef\u8bf7\u6c42 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 handleClient(clientSocket); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } \u00a0 \u00a0 \u00a0 \u00a0 } catch (IOException e) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 e.printStackTrace(); \u00a0 \u00a0 \u00a0 \u00a0 } \u00a0 \u00a0 } \u00a0 \u00a0\u00a0 \u00a0 \u00a0 private static void handleClient(Socket clientSocket) { \u00a0 \u00a0 \u00a0 \u00a0 try ( \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 BufferedReader in &#061; new BufferedReader( \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 new InputStreamReader(clientSocket.getInputStream())); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 PrintWriter out &#061; new PrintWriter(clientSocket.getOutputStream(), true) \u00a0 \u00a0 \u00a0 \u00a0 ) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u8bfb\u53d6\u5ba2\u6237\u7aef\u6d88\u606f \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 String message &#061; in.readLine(); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 System.out.println(&#034;Received from client: &#034; &#043; message); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u53d1\u9001\u54cd\u5e94 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 out.println(&#034;Hello Client! Your message: &#034; &#043; message); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u5173\u95ed\u8fde\u63a5&#xff08;\u77ed\u94fe\u63a5\u7279\u70b9&#xff09; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 clientSocket.close(); \u00a0 \u00a0 \u00a0 \u00a0 } catch (IOException e) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 e.printStackTrace(); \u00a0 \u00a0 \u00a0 \u00a0 } \u00a0 \u00a0 } }<\/p>\n<p>\u89c2\u4e86\u522b\u4eba\u5199\u7684\u4ee3\u7801\u540e\u6211\u81ea\u5df1\u53c8\u7a81\u7136\u6709\u4e86\u60f3\u6cd5&#xff0c;\u662f\u4e0d\u662f\u540e\u7aef\u53ef\u4ee5\u6709\u591a\u4e2a\u7aef\u53e3&#xff0c;\u8d1f\u8d23\u4e0d\u540c\u7684\u4e1a\u52a1&#xff0c;\u4e8e\u662f\u6211\u8fdb\u884c\u4e86\u67e5\u8be2&#xff0c;\u4ee5\u4e0b\u4fbf\u662f\u6211\u7684\u7406\u89e3\u3002<\/p>\n<h3>\u540e\u7aef\u591a\u7aef\u53e3<\/h3>\n<p>\u5bf9\u4e8e\u540e\u7aef\u591a\u4e2a\u7aef\u53e3&#xff0c;\u6bcf\u4e2a\u7aef\u53e3\u90fd\u6709\u81ea\u5df1\u8d1f\u8d23\u7684\u4e1a\u52a1&#xff0c;\u53ef\u4ee5\u6709\u77ed\u94fe\u63a5\u8bf7\u6c42\u7aef\u53e3&#xff0c;\u957f\u8fde\u63a5\u5efa\u7acb\u7aef\u53e3&#xff0c;\u4ee5\u53ca\u8d44\u6e90\u7b49\u5176\u4ed6\u4e1a\u52a1\u8bf7\u6c42\u7aef\u53e3\u3002<\/p>\n<h4 style=\"background-color:transparent\">(1)\u4f18\u70b9<\/h4>\n<p>a.\u4e1a\u52a1\u9700\u6c42\u591a\u6837\u5316<\/p>\n<p>b.\u6027\u80fd\u4f18\u5316<\/p>\n<p>c.\u5b89\u5168\u6027 &amp;&amp; \u9694\u79bb<\/p>\n<h3>2.\u957f\u8fde\u63a5<\/h3>\n<p>\u5bf9\u4e8e\u957f\u8fde\u63a5&#xff0c;\u6211\u7684\u7406\u89e3\u662f\u5f53\u7528\u6237\u767b\u5f55\u4e4b\u540e\u8fdb\u5165\u4e86\u4e3b\u754c\u9762\u65f6&#xff0c;\u957f\u8fde\u63a5\u4e5f\u8981\u5efa\u7acb\u4e86&#xff0c;\u800c\u5efa\u7acb\u957f\u8fde\u63a5&#xff0c;\u5219\u662f\u901a\u8fc7\u524d\u7aef\u548c\u540e\u7aefwhile\u5faa\u73af\u6765\u5efa\u7acb&#xff0c;\u6e90\u6e90\u4e0d\u65ad\u7684\u770b\u662f\u5426\u6709\u8bf7\u6c42\u7684\u4f20\u9012\u3002<\/p>\n<h4 style=\"background-color:transparent\">(1)\u957f\u8fde\u63a5\u7684\u4f18\u70b9<\/h4>\n<p>a.\u51cf\u5c11\u8fde\u63a5\u5efa\u7acb\u548c\u65ad\u5f00\u7684\u5f00\u9500<\/p>\n<p>b.\u9002\u5408\u9891\u7e41\u901a\u4fe1\u7684\u573a\u666f<\/p>\n<p>c.\u4fdd\u6301\u4f1a\u8bdd\u72b6\u6001<\/p>\n<p>d.\u66f4\u5feb\u7684\u54cd\u5e94\u901f\u5ea6<\/p>\n<h4>(2)\u957f\u8fde\u63a5\u7684\u7f3a\u70b9<\/h4>\n<p>a.\u5360\u7528\u670d\u52a1\u5668\u8d44\u6e90<\/p>\n<p>b.\u9700\u8981\u5fc3\u8df3\u673a\u5236\u7ef4\u62a4<\/p>\n<p>c.\u7f51\u7edc\u73af\u5883\u9002\u5e94\u6027\u8f83<\/p>\n<p>d.\u590d\u6742\u6027\u8f83\u9ad8<\/p>\n<h4>(3)\u957f\u8fde\u63a5\u7684\u5e94\u7528\u573a\u666f<\/h4>\n<p>a.\u5b9e\u65f6\u901a\u4fe1(qq,\u5fae\u4fe1\u8fd9\u79cd\u804a\u5929\u8f6f\u4ef6\u7b49)<\/p>\n<p>b.\u9ad8\u9891\u77ed\u6570\u636e\u4ea4\u4e92<\/p>\n<p>c.\u6570\u636e\u5e93\/\u7f13\u5b58\u8fde\u63a5\u6c60<\/p>\n<p>d.API\u7f51\u5173\/\u5fae\u670d\u52a1\u901a\u4fe1<\/p>\n<\/p>\n<p>\u957f\u8fde\u63a5\u57fa\u672c\u4ee3\u7801\u5b9e\u73b0<\/p>\n<p>\u7528\u6237\u7aef<\/p>\n<p>import java.io.*; import java.net.*; import java.util.concurrent.*;<\/p>\n<p>public class LongConnectionClient { \u00a0 \u00a0 private static final String HOST &#061; &#034;localhost&#034;; \u00a0 \u00a0 private static final int PORT &#061; 8888; \u00a0 \u00a0 private static final ScheduledExecutorService scheduler &#061;\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Executors.newScheduledThreadPool(1);<\/p>\n<p>\u00a0 \u00a0 public static void main(String[] args) { \u00a0 \u00a0 \u00a0 \u00a0 try { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Socket socket &#061; new Socket(HOST, PORT); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 socket.setSoTimeout(5000); \/\/ \u8bbe\u7f6e\u8bfb\u53d6\u8d85\u65f6 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 PrintWriter out &#061; new PrintWriter(socket.getOutputStream(), true); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 BufferedReader in &#061; new BufferedReader( \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 new InputStreamReader(socket.getInputStream())); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u53d1\u9001\u4e1a\u52a1\u6d88\u606f \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 for (int i &#061; 0; i &lt; 5; i&#043;&#043;) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 String message &#061; &#034;\u4e1a\u52a1\u6d88\u606f_&#034; &#043; i; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 out.println(message); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 String response &#061; in.readLine(); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 System.out.println(&#034;\u6536\u5230\u54cd\u5e94&#xff1a;&#034; &#043; response); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Thread.sleep(2000); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u5173\u95ed\u8fde\u63a5 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 scheduler.shutdown(); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 socket.close(); \u00a0 \u00a0 \u00a0 \u00a0 } catch (Exception e) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 e.printStackTrace(); \u00a0 \u00a0 \u00a0 \u00a0 } \u00a0 \u00a0 }<\/p>\n<p>\u00a0 \u00a0 private static void startHeartbeat(PrintWriter out) { \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u6bcf10\u79d2\u53d1\u9001\u4e00\u6b21\u5fc3\u8df3 \u00a0 \u00a0 \u00a0 \u00a0 scheduler.scheduleAtFixedRate(() -&gt; { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 try { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 out.println(&#034;HEARTBEAT&#034;); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 System.out.println(&#034;\u53d1\u9001\u5fc3\u8df3&#034;); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } catch (Exception e) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 e.printStackTrace(); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } \u00a0 \u00a0 \u00a0 \u00a0 }, 0, 10, TimeUnit.SECONDS); \u00a0 \u00a0 } }<\/p>\n<p>\u670d\u52a1\u5668<\/p>\n<p>import java.io.*; import java.net.*; import java.util.concurrent.*;<\/p>\n<p>public class LongConnectionServer { \u00a0 \u00a0 private static final int PORT &#061; 8888; \u00a0 \u00a0 private static final int MAX_THREADS &#061; 100; \u00a0 \u00a0 private static final ExecutorService threadPool &#061; Executors.newFixedThreadPool(MAX_THREADS);<\/p>\n<p>\u00a0 \u00a0 public static void main(String[] args) { \u00a0 \u00a0 \u00a0 \u00a0 try (ServerSocket serverSocket &#061; new ServerSocket(PORT)) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 System.out.println(&#034;\u957f\u8fde\u63a5\u670d\u52a1\u7aef\u542f\u52a8&#xff0c;\u76d1\u542c\u7aef\u53e3&#xff1a;&#034; &#043; PORT); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 while (true) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Socket clientSocket &#061; serverSocket.accept(); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u8bbe\u7f6e\u8bfb\u5199\u8d85\u65f6\u65f6\u95f4&#xff08;\u6beb\u79d2&#xff09; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 clientSocket.setSoTimeout(30000); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u957f\u8fde\u63a5\u7ebf\u7a0b \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 threadPool.execute(new ClientHandler(clientSocket)); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } \u00a0 \u00a0 \u00a0 \u00a0 } catch (IOException e) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 e.printStackTrace(); \u00a0 \u00a0 \u00a0 \u00a0 } \u00a0 \u00a0 }<\/p>\n<p>\u00a0 \u00a0 static class ClientHandler implements Runnable { \u00a0 \u00a0 \u00a0 \u00a0 private final Socket socket; \u00a0 \u00a0 \u00a0 \u00a0 private long lastHeartbeatTime;<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 public ClientHandler(Socket socket) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 this.socket &#061; socket; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 this.lastHeartbeatTime &#061; System.currentTimeMillis(); \u00a0 \u00a0 \u00a0 \u00a0 }<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 &#064;Override \u00a0 \u00a0 \u00a0 \u00a0 public void run() { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 try (BufferedReader in &#061; new BufferedReader( \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 new InputStreamReader(socket.getInputStream())); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0PrintWriter out &#061; new PrintWriter( \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 socket.getOutputStream(), true)) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 System.out.println(&#034;\u5ba2\u6237\u7aef\u8fde\u63a5&#xff1a;&#034; &#043; socket.getRemoteSocketAddress());<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 String inputLine; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 while ((inputLine &#061; in.readLine()) !&#061; null) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u5fc3\u8df3\u68c0\u6d4b \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (&#034;HEARTBEAT&#034;.equals(inputLine)) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 lastHeartbeatTime &#061; System.currentTimeMillis(); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 out.println(&#034;HEARTBEAT_ACK&#034;); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 continue; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u5904\u7406\u4e1a\u52a1\u903b\u8f91 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 System.out.println(&#034;\u6536\u5230\u6d88\u606f&#xff1a;&#034; &#043; inputLine); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 String response &#061; &#034;\u5904\u7406\u7ed3\u679c&#xff1a;&#034; &#043; inputLine; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 out.println(response); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u68c0\u67e5\u8fde\u63a5\u662f\u5426\u8d85\u65f6&#xff08;30\u79d2\u65e0\u5fc3\u8df3&#xff09; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (System.currentTimeMillis() &#8211; lastHeartbeatTime &gt; 30000) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 System.out.println(&#034;\u8fde\u63a5\u8d85\u65f6&#xff0c;\u5173\u95ed\u8fde\u63a5&#034;); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 break; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } catch (SocketTimeoutException e) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 System.out.println(&#034;\u8bfb\u53d6\u8d85\u65f6&#xff0c;\u5173\u95ed\u8fde\u63a5&#034;); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } catch (IOException e) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 e.printStackTrace(); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } finally { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 try { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 socket.close(); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 System.out.println(&#034;\u8fde\u63a5\u5173\u95ed&#xff1a;&#034; &#043; socket.getRemoteSocketAddress()); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } catch (IOException e) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 e.printStackTrace(); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } \u00a0 \u00a0 \u00a0 \u00a0 } \u00a0 \u00a0 } }<\/p>\n<h2>\u4e8c\u3001\u5e8f\u5217\u5316<\/h2>\n<\/p>\n<h3>1.\u5e8f\u5217\u5316\u662f\u5c06\u5bf9\u8c61\u8f6c\u6362\u4e3a\u5b57\u8282\u6d41\u7684\u8fc7\u7a0b&#xff0c;\u4ee5\u4fbf\u5b58\u50a8\u6216\u4f20\u8f93&#xff1b;<\/h3>\n<h3>2.\u53cd\u5e8f\u5217\u5316\u5219\u662f\u5c06\u5b57\u8282\u6d41\u6062\u590d\u4e3a\u5bf9\u8c61\u3002\u5b83\u5728\u5206\u5e03\u5f0f\u7cfb\u7edf\u3001\u6570\u636e\u6301\u4e45\u5316\u548c\u7f51\u7edc\u901a\u4fe1\u4e2d\u8d77\u7740\u5173\u952e\u4f5c\u7528\u3002<\/h3>\n<h3>3. \u5e8f\u5217\u5316\u7684\u6838\u5fc3\u4f5c\u7528<\/h3>\n<h4>&#xff08;1&#xff09;\u5bf9\u8c61\u6301\u4e45\u5316&#xff08;\u5b58\u50a8\u5230\u6587\u4ef6\/\u6570\u636e\u5e93&#xff09;<\/h4>\n<ul>\n<li>\n<p>\u5c06\u5185\u5b58\u4e2d\u7684\u5bf9\u8c61\u4fdd\u5b58\u5230\u78c1\u76d8&#xff0c;\u7a0b\u5e8f\u91cd\u542f\u540e\u53ef\u6062\u590d\u3002<\/p>\n<\/li>\n<li>\n<p>\u793a\u4f8b&#xff1a;\u6e38\u620f\u5b58\u6863\u3001\u7528\u6237\u4f1a\u8bdd\u4fdd\u5b58\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>&#xff08;2&#xff09;\u7f51\u7edc\u4f20\u8f93&#xff08;\u8de8\u8fdb\u7a0b\/\u8de8\u673a\u5668\u901a\u4fe1&#xff09;<\/h4>\n<ul>\n<li>\n<p>\u5bf9\u8c61 \u2192 \u5b57\u8282\u6d41 \u2192 \u7f51\u7edc\u4f20\u8f93 \u2192 \u5b57\u8282\u6d41 \u2192 \u5bf9\u8c61\u3002<\/p>\n<\/li>\n<li>\n<p>\u793a\u4f8b&#xff1a;RPC\u8c03\u7528\u3001\u5fae\u670d\u52a1\u901a\u4fe1\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>&#xff08;3&#xff09;\u6df1\u62f7\u8d1d&#xff08;Deep Copy&#xff09;<\/h4>\n<ul>\n<li>\n<p>\u901a\u8fc7\u5e8f\u5217\u5316\/\u53cd\u5e8f\u5217\u5316\u5b9e\u73b0\u5bf9\u8c61\u7684\u5b8c\u5168\u590d\u5236\u3002<\/p>\n<\/li>\n<li>\n<p>\u793a\u4f8b&#xff1a;\u907f\u514dJava\u7684\u6d45\u62f7\u8d1d\u95ee\u9898\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>&#xff08;4&#xff09;\u8de8\u8bed\u8a00\u6570\u636e\u4ea4\u6362<\/h4>\n<ul>\n<li>\n<p>\u901a\u7528\u5e8f\u5217\u5316\u683c\u5f0f&#xff08;\u5982JSON\u3001Protocol Buffers&#xff09;\u652f\u6301\u4e0d\u540c\u8bed\u8a00\u89e3\u6790\u3002<\/p>\n<\/li>\n<li>\n<p>\u793a\u4f8b&#xff1a;Java\u670d\u52a1\u4e0ePython\u5ba2\u6237\u7aef\u901a\u4fe1\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>4. \u5e8f\u5217\u5316\u7684\u6838\u5fc3\u610f\u4e49<\/h3>\n<h4>&#xff08;1&#xff09;\u89e3\u51b3\u5bf9\u8c61\u4f20\u8f93\u95ee\u9898<\/h4>\n<ul>\n<li>\n<p>\u7f51\u7edc\u53ea\u80fd\u4f20\u8f93\u5b57\u8282\u6d41&#xff0c;\u5e8f\u5217\u5316\u662f\u5bf9\u8c61\u4f20\u8f93\u7684\u57fa\u7840\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>&#xff08;2&#xff09;\u5b9e\u73b0\u5206\u5e03\u5f0f\u7cfb\u7edf\u901a\u4fe1<\/h4>\n<ul>\n<li>\n<p>\u5fae\u670d\u52a1\u3001RPC\u3001\u6d88\u606f\u961f\u5217&#xff08;\u5982Kafka&#xff09;\u4f9d\u8d56\u5e8f\u5217\u5316\u4f20\u9012\u5bf9\u8c61\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>&#xff08;3&#xff09;\u4fdd\u8bc1\u6570\u636e\u4e00\u81f4\u6027<\/h4>\n<ul>\n<li>\n<p>\u5e8f\u5217\u5316\u534f\u8bae\u5b9a\u4e49\u4e86\u6570\u636e\u7684\u7f16\u7801\u89c4\u5219&#xff0c;\u907f\u514d\u89e3\u6790\u9519\u8bef\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>&#xff08;4&#xff09;\u63d0\u9ad8\u7cfb\u7edf\u6269\u5c55\u6027<\/h4>\n<ul>\n<li>\n<p>\u901a\u8fc7\u7248\u672c\u517c\u5bb9\u7684\u5e8f\u5217\u5316\u534f\u8bae&#xff08;\u5982Protobuf&#xff09;&#xff0c;\u652f\u6301\u5b57\u6bb5\u52a8\u6001\u589e\u51cf\u3002<\/p>\n<\/li>\n<\/ul>\n<h2>\u56db\u3001IO\u6d41<\/h2>\n<p>\u5728\u9879\u76ee\u4e2d&#xff0c;IO\u6d41\u4e3b\u8981\u7528\u4e8e\u6587\u4ef6\u8bfb\u5199\u548c\u7f51\u7edc\u6570\u636e\u4f20\u8f93&#xff0c;\u6838\u5fc3\u4f7f\u7528\u4e86\u4ee5\u4e0b\u7c7b&#xff1a;<\/p>\n<h3>1. \u5b57\u8282\u6d41&#xff08;Byte Streams&#xff09;<\/h3>\n<p>FileInputStream&#096;\/&#096;FileOutputStream\u00a0\u00a0 \u00a0 \u7528\u4e8e\u8bfb\u5199\u4e8c\u8fdb\u5236\u6587\u4ef6&#xff08;\u5982\u56fe\u7247\u3001\u89c6\u9891&#xff09;\u3002<\/p>\n<p>\/\/ \u8bfb\u53d6\u6587\u4ef6 \u00a0 try (FileInputStream fis &#061; new FileInputStream(&#034;file.bin&#034;)) { \u00a0 \u00a0 \u00a0 byte[] buffer &#061; new byte[1024]; \u00a0 \u00a0 \u00a0 int bytesRead; \u00a0 \u00a0 \u00a0 while ((bytesRead &#061; fis.read(buffer)) !&#061; -1) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u5904\u7406\u6570\u636e \u00a0 \u00a0 \u00a0 } \u00a0 }<\/p>\n<p>\u00a0 \/\/ \u5199\u5165\u6587\u4ef6 \u00a0 try (FileOutputStream fos &#061; new FileOutputStream(&#034;output.bin&#034;)) { \u00a0 \u00a0 \u00a0 fos.write(dataBytes); \u00a0 }<\/p>\n<h3>2. \u5b57\u7b26\u6d41&#xff08;Character Streams&#xff09;<\/h3>\n<p> BufferedReader&#096;\/&#096;BufferedWriter\u00a0<\/p>\n<p>\/\/ \u8bfb\u53d6\u6587\u672c\u6587\u4ef6 \u00a0 try (BufferedReader br &#061; new BufferedReader(new FileReader(&#034;config.txt&#034;))) { \u00a0 \u00a0 \u00a0 String line; \u00a0 \u00a0 \u00a0 while ((line &#061; br.readLine()) !&#061; null) { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 System.out.println(line); \u00a0 \u00a0 \u00a0 } \u00a0 }<\/p>\n<p>\u00a0 \/\/ \u5199\u5165\u6587\u672c\u6587\u4ef6 \u00a0 try (BufferedWriter bw &#061; new BufferedWriter(new FileWriter(&#034;log.txt&#034;))) { \u00a0 \u00a0 \u00a0 bw.write(&#034;Log message&#034;); \u00a0 \u00a0 \u00a0 bw.newLine(); \u00a0 }<\/p>\n<h3>3. \u5bf9\u8c61\u6d41&#xff08;Object Streams&#xff09;<\/h3>\n<p> ObjectInputStream&#096;\/&#096;ObjectOutputStream \u00a0 \u7528\u4e8e\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316Java\u5bf9\u8c61&#xff08;\u5982\u7528\u6237\u6570\u636e\u6301\u4e45\u5316&#xff09;\u3002<\/p>\n<p> \u00a0 \/\/ \u5e8f\u5217\u5316\u5bf9\u8c61\u5230\u6587\u4ef6 \u00a0 try (ObjectOutputStream oos &#061; new ObjectOutputStream( \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 new FileOutputStream(&#034;user.dat&#034;))) { \u00a0 \u00a0 \u00a0 oos.writeObject(user); \u00a0 }<\/p>\n<p>\u00a0 \/\/ \u4ece\u6587\u4ef6\u53cd\u5e8f\u5217\u5316\u5bf9\u8c61 \u00a0 try (ObjectInputStream ois &#061; new ObjectInputStream( \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 new FileInputStream(&#034;user.dat&#034;))) { \u00a0 \u00a0 \u00a0 User user &#061; (User) ois.readObject(); \u00a0 }<\/p>\n<h3>4. \u7f51\u7edcIO&#xff08;Socket\u6d41&#xff09;<\/h3>\n<p> Socket.getInputStream()&#096;\/&#096;Socket.getOutputStream() \u00a0 \u7528\u4e8e\u7f51\u7edc\u901a\u4fe1&#xff0c;\u7ed3\u5408&#096;BufferedReader&#096;\u548c&#096;PrintWriter&#096;\u5904\u7406\u6587\u672c\u534f\u8bae\u3002<\/p>\n<p>\/\/ \u670d\u52a1\u7aef\u8bfb\u53d6\u5ba2\u6237\u7aef\u6570\u636e \u00a0 try (BufferedReader in &#061; new BufferedReader( \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 new InputStreamReader(socket.getInputStream()))) { \u00a0 \u00a0 \u00a0 String message &#061; in.readLine(); \u00a0 }<\/p>\n<p>\u00a0 \/\/ \u5ba2\u6237\u7aef\u53d1\u9001\u6570\u636e\u5230\u670d\u52a1\u7aef \u00a0 try (PrintWriter out &#061; new PrintWriter( \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 socket.getOutputStream(), true)) { \u00a0 \u00a0 \u00a0 out.println(&#034;Hello Server!&#034;); \u00a0 }<\/p>\n<h2>\u4e94\u3001\u591a\u7ebf\u7a0b\u5728\u9879\u76ee\u4e2d\u7684\u5e94\u7528<\/h2>\n<p> \u591a\u7ebf\u7a0b\u4e3b\u8981\u7528\u4e8e\u5e76\u53d1\u5904\u7406\u5ba2\u6237\u7aef\u8bf7\u6c42\u548c\u5f02\u6b65\u4efb\u52a1\u3002<\/p>\n<\/p>\n<h3>1. \u7ebf\u7a0b\u6c60\u7ba1\u7406<\/h3>\n<p> ExecutorService \u00a0 \u907f\u514d\u9891\u7e41\u521b\u5efa\/\u9500\u6bc1\u7ebf\u7a0b&#xff0c;\u63d0\u5347\u6027\u80fd\u3002<\/p>\n<p>ExecutorService threadPool &#061; Executors.newFixedThreadPool(10); \u00a0 threadPool.execute(() -&gt; { \u00a0 \u00a0 \u00a0 \/\/ \u5904\u7406\u5ba2\u6237\u7aef\u8bf7\u6c42 \u00a0 });<\/p>\n<h3>2. \u7ebf\u7a0b\u540c\u6b65<\/h3>\n<p> synchronized&#096;\u5173\u952e\u5b57 \u00a0 \u4fdd\u62a4\u5171\u4eab\u8d44\u6e90&#xff08;\u5982\u6570\u636e\u5e93\u8fde\u63a5\u6c60&#xff09;\u3002 \u00a0<\/p>\n<p>public synchronized void updateData() { \u00a0 \u00a0 \u00a0 \/\/ \u7ebf\u7a0b\u5b89\u5168\u64cd\u4f5c \u00a0 }<\/p>\n<h2>\u516d\u3001\u6587\u4ef6\u5206\u7247\u4e0a\u4f20\/\u4e0b\u8f7d<\/h2>\n<p> \u901a\u8fc7IO\u6d41\u5b9e\u73b0\u5927\u6587\u4ef6\u7684\u5206\u5757\u5904\u7406\u3002<\/p>\n<\/p>\n<h3>1. \u6587\u4ef6\u5206\u7247\u4e0a\u4f20<\/h3>\n<p> \/\/ \u5ba2\u6237\u7aef\u5206\u7247\u53d1\u9001 try (FileInputStream fis &#061; new FileInputStream(&#034;large_file.zip&#034;); \u00a0 \u00a0 \u00a0BufferedInputStream bis &#061; new BufferedInputStream(fis)) { \u00a0 \u00a0 byte[] buffer &#061; new byte[1024 * 1024]; \/\/ 1MB\u5206\u7247 \u00a0 \u00a0 int bytesRead; \u00a0 \u00a0 while ((bytesRead &#061; bis.read(buffer)) !&#061; -1) { \u00a0 \u00a0 \u00a0 \u00a0 socket.getOutputStream().write(buffer, 0, bytesRead); \u00a0 \u00a0 } }<\/p>\n<h3>2. \u670d\u52a1\u7aef\u5206\u7247\u63a5\u6536<\/h3>\n<p> try (FileOutputStream fos &#061; new FileOutputStream(&#034;received_file.zip&#034;); \u00a0 \u00a0 \u00a0BufferedOutputStream bos &#061; new BufferedOutputStream(fos)) { \u00a0 \u00a0 byte[] buffer &#061; new byte[1024 * 1024]; \u00a0 \u00a0 int bytesRead; \u00a0 \u00a0 while ((bytesRead &#061; socket.getInputStream().read(buffer)) !&#061; -1) { \u00a0 \u00a0 \u00a0 \u00a0 bos.write(buffer, 0, bytesRead); \u00a0 \u00a0 } }<\/p>\n<\/p>\n<h2>\u4e03\u3001MySQL\u6570\u636e\u5e93\u64cd\u4f5c<\/h2>\n<p> \u4f7f\u7528JDBC\u8fdb\u884cCRUD\u64cd\u4f5c\u3002<\/p>\n<h3>1. \u6570\u636e\u5e93\u8fde\u63a5<\/h3>\n<p> String url &#061; &#034;jdbc:mysql:\/\/localhost:3306\/mydb&#034;; String user &#061; &#034;root&#034;; String password &#061; &#034;123456&#034;; try (Connection conn &#061; DriverManager.getConnection(url, user, password)) { \u00a0 \u00a0 \/\/ \u6267\u884cSQL }<\/p>\n<h3>2. \u67e5\u8be2\u6570\u636e<\/h3>\n<\/p>\n<p> String sql &#061; &#034;SELECT * FROM users WHERE id &#061; ?&#034;; try (PreparedStatement stmt &#061; conn.prepareStatement(sql)) { \u00a0 \u00a0 stmt.setInt(1, 1001); \u00a0 \u00a0 ResultSet rs &#061; stmt.executeQuery(); \u00a0 \u00a0 while (rs.next()) { \u00a0 \u00a0 \u00a0 \u00a0 String name &#061; rs.getString(&#034;name&#034;); \u00a0 \u00a0 } }<\/p>\n<h3>3. \u63d2\u5165\/\u66f4\u65b0\u6570\u636e<\/h3>\n<p> String sql &#061; &#034;INSERT INTO users (name, age) VALUES (?, ?)&#034;; try (PreparedStatement stmt &#061; conn.prepareStatement(sql)) { \u00a0 \u00a0 stmt.setString(1, &#034;Alice&#034;); \u00a0 \u00a0 stmt.setInt(2, 25); \u00a0 \u00a0 stmt.executeUpdate(); }<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p> | \u6280\u672f\u00a0\u00a0\u00a0 \u00a0 \u00a0| \u5728\u9879\u76ee\u4e2d\u7684\u5e94\u7528\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 | |&#8212;&#8212;&#8212;&#8212;-|&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;| | IO\u6d41\u00a0\u00a0 \u00a0 \u00a0 | \u6587\u4ef6\u8bfb\u5199\u3001\u7f51\u7edc\u6570\u636e\u4f20\u8f93\u3001\u5bf9\u8c61\u5e8f\u5217\u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | | \u591a\u7ebf\u7a0b\u00a0 \u00a0 | \u5e76\u53d1\u5904\u7406\u5ba2\u6237\u7aef\u8bf7\u6c42\u4efb\u52a1\u6267\u884c \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | | \u6587\u4ef6\u5206\u7247 | \u5927\u6587\u4ef6\u7684\u4e0a\u4f20\u4e0e\u4e0b\u8f7d \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | | MySQL\u00a0 \u00a0| \u7528\u6237\u6570\u636e\u5b58\u50a8\u3001\u67e5\u8be2\u548c\u66f4\u65b0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | | JavaFX\u00a0\u00a0 | \u6784\u5efa\u56fe\u5f62\u754c\u9762&#xff0c;\u4e0e\u540e\u7aefSocket\/\u6570\u636e\u5e93\u4ea4\u4e92\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0|<\/p>\n<\/p>\n<h3>\u901a\u8fc7\u7ed3\u5408\u8fd9\u4e9b\u6280\u672f&#xff0c;\u9879\u76ee\u5b9e\u73b0\u4e86&#xff1a; \u00a0<\/h3>\n<p> 1.\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u7aef\u7684\u7a33\u5b9a\u901a\u4fe1&#xff08;\u957f\u77ed\u94fe\u63a5\u7ed3\u5408&#xff09; \u00a0 \u00a02.\u9ad8\u6548\u6587\u4ef6\u4f20\u8f93&#xff08;\u5206\u7247\u5904\u7406&#xff09; \u00a0 \u00a03.\u6570\u636e\u6301\u4e45\u5316&#xff08;MySQL &#043; \u5e8f\u5217\u5316&#xff09; \u00a0 \u00a04.\u7528\u6237\u53cb\u597d\u7684\u56fe\u5f62\u754c\u9762&#xff08;JavaFX&#xff09;<\/p>\n<\/p>\n<\/p>\n<\/p>\n<h2>\u4e00\u3001\u7b97\u6cd5\u9898<\/h2>\n<h3>1.<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"946\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520083242-682c3e2acb0c3.png\" width=\"625\" \/><\/p>\n<p>\u89e3\u9898\u601d\u8def&#xff1a;\u6b63\u5e38\u7684\u5e76\u67e5\u96c6&#xff0c;\u52a0\u4e00\u4e2amap\u6765\u5b9e\u73b0string-&gt;int\u5373\u53ef<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;vector&gt;<br \/>\n#include &lt;stack&gt;<br \/>\n#include &lt;queue&gt;<br \/>\n#include &lt;climits&gt;<br \/>\n#include &lt;algorithm&gt;<br \/>\n#include &lt;map&gt;<br \/>\n#define ll long long<br \/>\nusing namespace std;<\/p>\n<p>int n, m, p;<\/p>\n<p>int find(int x, vector&lt;int&gt;&amp; parent) {<br \/>\n    if (parent[x] !&#061; x)<br \/>\n        parent[x] &#061; find(parent[x], parent);<br \/>\n    return parent[x];<br \/>\n}<\/p>\n<p>void setUnion(int a, int b, vector&lt;int&gt;&amp; parent, vector&lt;int&gt;&amp; rank) {<br \/>\n    a &#061; find(a,parent);<br \/>\n    b &#061; find(b,parent);<\/p>\n<p>    if (a &#061;&#061; b)<br \/>\n        return;<\/p>\n<p>    int x1 &#061; min(a, b);<br \/>\n    int x2 &#061; max(a, b);<br \/>\n    if (rank[x1] &gt; rank[x2])<br \/>\n        parent[x2] &#061; x1;<br \/>\n    else if (rank[x1] &lt; rank[x2])<br \/>\n        parent[x2] &#061; x1;<br \/>\n    else {<br \/>\n        parent[x1] &#061; x2;<br \/>\n        rank[x2]&#043;&#043;;<br \/>\n    }<\/p>\n<p>}<\/p>\n<p>bool isConnect(int a, int b, vector&lt;int&gt;&amp; parent) {<br \/>\n    a &#061; find(a, parent);<br \/>\n    b &#061; find(b, parent);<br \/>\n    return a &#061;&#061; b;<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    cin &gt;&gt; n &gt;&gt; m;<br \/>\n    vector&lt;int&gt;parent(n &#043; 1, 0); \/\/ \u8282\u70b9\u7684\u4e0a\u4e00\u7ea7<br \/>\n    map&lt;string,int&gt; tt;<br \/>\n    vector&lt;int&gt;rank(n &#043; 1, 0); \/\/ \u5efa\u7acb\u6700\u5c0f\u7684\u6811<\/p>\n<p>    for (int i &#061; 1; i &lt;&#061; n; i&#043;&#043;) { \/\/ \u5148\u6307\u5411\u81ea\u8eab<br \/>\n        parent[i] &#061; i;<br \/>\n        string s; cin &gt;&gt; s;<br \/>\n        tt[s] &#061; i;<br \/>\n    }<\/p>\n<p>    for (int i &#061; 1; i &lt;&#061; m; i&#043;&#043;) { \/\/ \u5efa\u7acb\u4eb2\u621a\u5173\u7cfb<br \/>\n        string a, b; cin &gt;&gt; a &gt;&gt; b;<br \/>\n        int x1 &#061; tt[a], x2 &#061; tt[b];<br \/>\n        setUnion(x1, x2, parent, rank);<br \/>\n    }<br \/>\n    cin &gt;&gt; p;<br \/>\n    for (int i &#061; 1; i &lt;&#061; p; i&#043;&#043;) {<br \/>\n        string a, b; cin &gt;&gt; a &gt;&gt; b;<br \/>\n        int x1 &#061; tt[a], x2 &#061; tt[b];<br \/>\n        if (isConnect(x1, x2, parent))<br \/>\n            cout &lt;&lt; &#034;Yes.&#034; &lt;&lt; endl;<br \/>\n        else<br \/>\n            cout &lt;&lt; &#034;No.&#034; &lt;&lt; endl;<br \/>\n    }<\/p>\n<p>    return 0;<br \/>\n} <\/p>\n<h3>\u00a02.<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"755\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520083243-682c3e2b154f2.png\" width=\"668\" \/><\/p>\n<p>\u89e3\u9898\u601d\u8def&#xff1a; \u5e76\u67e5\u96c6&#xff0c;\u9650\u5b9a\u4e86\u5408\u5e76\u6761\u4ef6&#xff0c;\u6839\u636e\u9898\u76ee\u7684\u5408\u5e76\u6761\u4ef6\u5408\u6210\u5373\u53ef<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;vector&gt;<br \/>\n#include &lt;stack&gt;<br \/>\n#include &lt;queue&gt;<br \/>\n#include &lt;climits&gt;<br \/>\n#include &lt;algorithm&gt;<br \/>\n#include &lt;map&gt;<br \/>\n#define ll long long<br \/>\nusing namespace std;<\/p>\n<p>map&lt;string, string&gt; parent;<\/p>\n<p>\/\/ \u67e5\u627e\u5e76\u8fd4\u56dename\u7684\u6700\u65e9\u7956\u5148&#xff0c;\u5e76\u8fdb\u884c\u8def\u5f84\u538b\u7f29<br \/>\nstring findAncestor(string name) {<br \/>\n    if (name !&#061; parent[name]) {<br \/>\n        parent[name] &#061; findAncestor(parent[name]);<br \/>\n    }<br \/>\n    return parent[name];<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    char prefix;<br \/>\n    string name;<br \/>\n    string current_parent;<\/p>\n<p>    cin &gt;&gt; prefix;<br \/>\n    while (prefix !&#061; &#039;$&#039;) {<br \/>\n        cin &gt;&gt; name;<br \/>\n        if (prefix &#061;&#061; &#039;#&#039;) {<br \/>\n            current_parent &#061; name;<br \/>\n            if (parent.find(name) &#061;&#061; parent.end()) {<br \/>\n                parent[name] &#061; name; \/\/ \u521d\u59cb\u5316\u7236\u4eb2\u4e3a\u81ea\u8eab<br \/>\n            }<br \/>\n        } else if (prefix &#061;&#061; &#039;&#043;&#039;) {<br \/>\n            parent[name] &#061; current_parent;<br \/>\n        } else if (prefix &#061;&#061; &#039;?&#039;) {<br \/>\n            cout &lt;&lt; name &lt;&lt; &#039; &#039; &lt;&lt; findAncestor(name) &lt;&lt; endl;<br \/>\n        }<br \/>\n        cin &gt;&gt; prefix;<br \/>\n    }<\/p>\n<p>    return 0;<br \/>\n} <\/p>\n<h3>3.<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"661\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520083243-682c3e2b2e927.png\" width=\"636\" \/><\/p>\n<p>\u89e3\u9898\u601d\u8def&#xff1a;\u628a\u9898\u76ee\u770b\u6210\u56fe&#xff0c;\u6bcf\u4e2a\u70b9\u90fd\u662f\u9876\u70b9&#xff0c;\u8ddd\u79bb\u90fd\u662f\u6743\u91cd&#xff0c;\u5c31\u53ef\u4ee5\u7528kruskal\u4e86\u3002<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;algorithm&gt;<br \/>\n#include &lt;vector&gt;<br \/>\n#include &lt;cmath&gt;<br \/>\n#include &lt;iomanip&gt;<br \/>\nusing namespace std;<\/p>\n<p>struct Edge {<br \/>\n    int u, v;<br \/>\n    double w;<br \/>\n    bool operator&lt;(const Edge&amp; other) const {<br \/>\n        return w &lt; other.w;<br \/>\n    }<br \/>\n};<\/p>\n<p>vector&lt;Edge&gt; edges;<br \/>\nvector&lt;int&gt; parent;<br \/>\nint S, P;<br \/>\nvector&lt;pair&lt;int, int&gt;&gt; d; <\/p>\n<p>int find(int x) {<br \/>\n    if (parent[x] !&#061; x) {<br \/>\n        parent[x] &#061; find(parent[x]);<br \/>\n    }<br \/>\n    return parent[x];<br \/>\n}<\/p>\n<p>void unionset(int x, int y) {<br \/>\n    int rootX &#061; find(x);<br \/>\n    int rootY &#061; find(y);<br \/>\n    if (rootX !&#061; rootY) {<br \/>\n        parent[rootY] &#061; rootX;<br \/>\n    }<br \/>\n}<\/p>\n<p>double kruskal() {<\/p>\n<p>    parent.resize(P &#043; 1);<br \/>\n    for (int i &#061; 1; i &lt;&#061; P; i&#043;&#043;) {<br \/>\n        parent[i] &#061; i;<br \/>\n    }<\/p>\n<p>    sort(edges.begin(), edges.end());<\/p>\n<p>    double ans &#061; 0.0;<br \/>\n    int k &#061; P &#8211; S; <\/p>\n<p>    for (const auto&amp; edge : edges) {<br \/>\n        if (find(edge.u) !&#061; find(edge.v)) {<br \/>\n            unionset(edge.u, edge.v);<br \/>\n            ans &#061; edge.w;<br \/>\n            k&#8211;;<br \/>\n            if (k &#061;&#061; 0) {<br \/>\n                break;<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    return ans;<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    cin &gt;&gt; S &gt;&gt; P;<br \/>\n    d.resize(P &#043; 1);<\/p>\n<p>    for (int i &#061; 1; i &lt;&#061; P; i&#043;&#043;) {<br \/>\n        cin &gt;&gt; d[i].first &gt;&gt; d[i].second;<br \/>\n    }<\/p>\n<p>    for (int i &#061; 1; i &lt;&#061; P; i&#043;&#043;) {<br \/>\n        for (int j &#061; i &#043; 1; j &lt;&#061; P; j&#043;&#043;) {<br \/>\n            double dx &#061; d[i].first &#8211; d[j].first;<br \/>\n            double dy &#061; d[i].second &#8211; d[j].second;<br \/>\n            double dis &#061; sqrt(dx * dx &#043; dy * dy);<br \/>\n            edges.push_back({ i, j, dis });<br \/>\n        }<br \/>\n    }<\/p>\n<p>    double ans &#061; kruskal();<\/p>\n<p>    cout &lt;&lt; fixed &lt;&lt; setprecision(2) &lt;&lt; ans &lt;&lt; endl;<\/p>\n<p>    return 0;<br \/>\n} <\/p>\n<h3>\u00a04.<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"578\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520083243-682c3e2b46c35.png\" width=\"654\" \/><\/p>\n<p>\u89e3\u9898\u601d\u8def:\u5f00\u59cb\u60f3\u4e86\u597d\u4e45&#xff0c;\u53d1\u73b0N&lt;&#061;6,\u8fd9\u4e2a\u6570\u91cf\u597d\u50cf\u53ef\u4ee5\u76f4\u63a5\u904d\u5386\u6240\u6709\u7684\u60c5\u51b5\u6765\u8ba8\u8bba&#xff0c;\u4f46\u662f\u5bf9\u4e8e\u9762\u79ef\u7684\u8ba1\u7b97\u8fd8\u662f\u6709\u70b9\u8ff7&#xff0c;\u5c31\u770b\u4e86\u4e0b\u522b\u4eba\u7684\u601d\u8def\u3002\u8ba9\u653e\u4e0b\u7684\u6cb9\u6ef4\u5c3d\u53ef\u80fd\u7684\u6269\u5927&#xff0c;\u76f8\u52a0\u6240\u6709\u7684\u9762\u79ef&#xff0c;\u6bcf\u6b21\u679a\u4e3e\u90fd\u53d6\u9762\u79ef\u7684\u6700\u5927\u503c<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;vector&gt;<br \/>\n#include &lt;cmath&gt;<br \/>\n#include &lt;algorithm&gt;<br \/>\n#include &lt;iomanip&gt;<\/p>\n<p>using namespace std;<\/p>\n<p>double area(int N, const vector&lt;pair&lt;int, int&gt;&gt;&amp; points, int left, int right, int bottom, int top) {<br \/>\n    double max_total_area &#061; 0.0;<br \/>\n    vector&lt;int&gt; indices(N);<br \/>\n    for (int i &#061; 0; i &lt; N; &#043;&#043;i) {<br \/>\n        indices[i] &#061; i;<br \/>\n    }<\/p>\n<p>    do {<br \/>\n        vector&lt;double&gt; radii(N, 0.0);<br \/>\n        double total_area &#061; 0.0;<br \/>\n        for (int i &#061; 0; i &lt; N; &#043;&#043;i) {<br \/>\n            int x &#061; points[indices[i]].first;<br \/>\n            int y &#061; points[indices[i]].second;<br \/>\n            double min_r &#061; min({x &#8211; left, right &#8211; x, y &#8211; bottom, top &#8211; y});<br \/>\n            for (int j &#061; 0; j &lt; i; &#043;&#043;j) {<br \/>\n                int xj &#061; points[indices[j]].first;<br \/>\n                int yj &#061; points[indices[j]].second;<br \/>\n                double dx &#061; x &#8211; xj;<br \/>\n                double dy &#061; y &#8211; yj;<br \/>\n                double distance &#061; sqrt(dx * dx &#043; dy * dy);<br \/>\n                min_r &#061; min(min_r, distance &#8211; radii[j]);<br \/>\n                if (min_r &lt;&#061; 0) break;<br \/>\n            }<br \/>\n            if (min_r &gt; 0) {<br \/>\n                radii[i] &#061; min_r;<br \/>\n                total_area &#043;&#061; M_PI * min_r * min_r;<br \/>\n            }<br \/>\n        }<br \/>\n        if (total_area &gt; max_total_area) {<br \/>\n            max_total_area &#061; total_area;<br \/>\n        }<br \/>\n    } while (next_permutation(indices.begin(), indices.end()));<\/p>\n<p>    double area_rect &#061; (right &#8211; left) * (top &#8211; bottom);<br \/>\n    return area_rect &#8211; max_total_area;<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    int N;<br \/>\n    cin &gt;&gt; N;<br \/>\n    int x1, y1, x2, y2;<br \/>\n    cin &gt;&gt; x1 &gt;&gt; y1 &gt;&gt; x2 &gt;&gt; y2;<br \/>\n    int left &#061; min(x1, x2);<br \/>\n    int right &#061; max(x1, x2);<br \/>\n    int bottom &#061; min(y1, y2);<br \/>\n    int top &#061; max(y1, y2);<\/p>\n<p>    vector&lt;pair&lt;int, int&gt;&gt; points(N);<br \/>\n    for (int i &#061; 0; i &lt; N; &#043;&#043;i) {<br \/>\n        cin &gt;&gt; points[i].first &gt;&gt; points[i].second;<br \/>\n    }<\/p>\n<p>    sort(points.begin(), points.end());<br \/>\n    double remaining_area &#061; area(N, points, left, right, bottom, top);<br \/>\n    cout &lt;&lt; static_cast&lt;int&gt;(round(remaining_area)) &lt;&lt; endl;<\/p>\n<p>    return 0;<br \/>\n} <\/p>\n<h3>5.<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"730\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520083243-682c3e2b5dea4.png\" width=\"680\" \/><\/p>\n<p>\u89e3\u9898\u601d\u8def&#xff1a;\u7b2c\u4e00\u6b21\u5199\u8fd9\u79cd\u9898&#xff0c;\u6211\u6700\u5f00\u59cb\u5c31\u662f\u76f4\u63a5\u7528dfs\u6765\u641c\u7d22&#xff0c;\u4f46\u662f\u65f6\u95f4\u8d85\u9650&#xff0c;\u7136\u540e\u6211\u770b\u4e86\u4e00\u4e0b\u522b\u4eba\u7684\u601d\u8def&#xff0c;\u53ef\u4ee5\u7528\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u5b58\u50a8\u5df2\u7ecf\u77e5\u9053\u7684\u6bcf\u4e2a\u7684\u4f4d\u7f6e\u7684\u6700\u5927\u503c&#xff0c;\u5f53dfs\u5230\u8fd9\u4e2a\u4f4d\u7f6e&#xff0c;\u76f4\u63a5\u4ece\u4e8c\u7ef4\u6570\u7ec4\u91cc\u53d6\u51fa\u6765\u5c31\u884c\u4e86&#xff0c;\u8fd9\u4e2a\u65b9\u6cd5\u4e5f\u662f\u8bb0\u5fc6\u5316\u641c\u7d22<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;vector&gt;<br \/>\n#include &lt;stack&gt;<br \/>\n#include &lt;queue&gt;<br \/>\n#include &lt;climits&gt;<br \/>\n#include &lt;algorithm&gt;<br \/>\n#include &lt;map&gt;<br \/>\n#define ll long long<br \/>\nusing namespace std;<\/p>\n<p>\/\/ \u5b9a\u4e49\u56db\u4e2a\u65b9\u5411<br \/>\nint dirs[4][2] &#061; {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};<\/p>\n<p>\/\/ \u5168\u5c40\u53d8\u91cf\u5b58\u50a8\u77e9\u9635\u548cdp\u6570\u7ec4<br \/>\nvector&lt;vector&lt;int&gt;&gt; matrix;<br \/>\nvector&lt;vector&lt;int&gt;&gt; dp;<br \/>\nint R, C;<\/p>\n<p>\/\/ DFS\u51fd\u6570&#xff0c;\u8fd4\u56de\u4ece(x, y)\u51fa\u53d1\u7684\u6700\u957f\u6ed1\u5761\u957f\u5ea6<br \/>\nint dfs(int x, int y) {<br \/>\n    \/\/ \u5982\u679c\u5df2\u7ecf\u8ba1\u7b97\u8fc7&#xff0c;\u76f4\u63a5\u8fd4\u56de\u7ed3\u679c<br \/>\n    if (dp[x][y] !&#061; -1) {<br \/>\n        return dp[x][y];<br \/>\n    }<\/p>\n<p>    \/\/ \u521d\u59cb\u5316\u4e3a1&#xff0c;\u56e0\u4e3a\u81f3\u5c11\u53ef\u4ee5\u6ed1\u5230\u81ea\u5df1<br \/>\n    dp[x][y] &#061; 1;<\/p>\n<p>    \/\/ \u904d\u5386\u56db\u4e2a\u65b9\u5411<br \/>\n    for (int i &#061; 0; i &lt; 4; &#043;&#043;i) {<br \/>\n        int newX &#061; x &#043; dirs[i][0];<br \/>\n        int newY &#061; y &#043; dirs[i][1];<br \/>\n        \/\/ \u68c0\u67e5\u8fb9\u754c\u6761\u4ef6\u548c\u9ad8\u5ea6\u662f\u5426\u4e0b\u964d<br \/>\n        if (newX &gt;&#061; 0 &amp;&amp; newX &lt; R &amp;&amp; newY &gt;&#061; 0 &amp;&amp; newY &lt; C &amp;&amp; matrix[newX][newY] &lt; matrix[x][y]) {<br \/>\n            \/\/ \u9012\u5f52\u8ba1\u7b97\u76f8\u90bb\u70b9\u7684\u6700\u957f\u6ed1\u5761\u957f\u5ea6&#xff0c;\u5e76\u66f4\u65b0\u5f53\u524d\u70b9\u7684dp\u503c<br \/>\n            dp[x][y] &#061; max(dp[x][y], dfs(newX, newY) &#043; 1);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    return dp[x][y];<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    \/\/ \u8bfb\u53d6\u884c\u6570\u548c\u5217\u6570<br \/>\n    cin &gt;&gt; R &gt;&gt; C;<br \/>\n    matrix.assign(R, vector&lt;int&gt;(C));<br \/>\n    for (int i &#061; 0; i &lt; R; &#043;&#043;i) {<br \/>\n        for (int j &#061; 0; j &lt; C; &#043;&#043;j) {<br \/>\n            cin &gt;&gt; matrix[i][j];<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ \u521d\u59cb\u5316dp\u6570\u7ec4\u4e3a-1&#xff0c;\u8868\u793a\u672a\u8ba1\u7b97<br \/>\n    dp.assign(R, vector&lt;int&gt;(C, -1));<\/p>\n<p>    \/\/ \u904d\u5386\u6240\u6709\u70b9&#xff0c;\u8ba1\u7b97\u6700\u957f\u6ed1\u5761\u957f\u5ea6<br \/>\n    int maxLength &#061; 0;<br \/>\n    for (int i &#061; 0; i &lt; R; &#043;&#043;i) {<br \/>\n        for (int j &#061; 0; j &lt; C; &#043;&#043;j) {<br \/>\n            if (dp[i][j] &#061;&#061; -1) { \/\/ \u5982\u679c\u5c1a\u672a\u8ba1\u7b97<br \/>\n                dfs(i, j);<br \/>\n            }<br \/>\n            maxLength &#061; max(maxLength, dp[i][j]);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ \u8f93\u51fa\u7ed3\u679c<br \/>\n    cout &lt;&lt; maxLength &lt;&lt; endl;<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb788\u6b21\uff0c\u70b9\u8d5e21\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u6280\u672f       | \u5728\u9879\u76ee\u4e2d\u7684\u5e94\u7528                                                     || IO\u6d41       | \u6587\u4ef6\u8bfb\u5199\u3001\u7f51\u7edc\u6570\u636e\u4f20\u8f93\u3001\u5bf9\u8c61\u5e8f\u5217                     || \u591a\u7ebf\u7a0b    | \u5e76\u53d1\u5904\u7406\u5ba2\u6237\u7aef\u8bf7\u6c42\u4efb\u52a1\u6267\u884c                     || \u6587\u4ef6\u5206\u7247 | \u5927\u6587\u4ef6\u7684\u4e0a\u4f20\u4e0e\u4e0b\u8f7d                                              |<\/p>\n","protected":false},"author":2,"featured_media":38458,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[371],"topic":[],"class_list":["post-38463","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-371"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JAVAfx\u9879\u76ee\u603b\u7ed3 &amp;&amp; \u7b97\u6cd5\u9898 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/38463.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JAVAfx\u9879\u76ee\u603b\u7ed3 &amp;&amp; \u7b97\u6cd5\u9898 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb788\u6b21\uff0c\u70b9\u8d5e21\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u6280\u672f    | \u5728\u9879\u76ee\u4e2d\u7684\u5e94\u7528                           || IO\u6d41    | \u6587\u4ef6\u8bfb\u5199\u3001\u7f51\u7edc\u6570\u636e\u4f20\u8f93\u3001\u5bf9\u8c61\u5e8f\u5217           || \u591a\u7ebf\u7a0b  | \u5e76\u53d1\u5904\u7406\u5ba2\u6237\u7aef\u8bf7\u6c42\u4efb\u52a1\u6267\u884c           || \u6587\u4ef6\u5206\u7247 | \u5927\u6587\u4ef6\u7684\u4e0a\u4f20\u4e0e\u4e0b\u8f7d                       |\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/38463.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-20T08:32:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520083242-682c3e2acb0c3.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38463.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/38463.html\",\"name\":\"JAVAfx\u9879\u76ee\u603b\u7ed3 &amp;&amp; \u7b97\u6cd5\u9898 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-20T08:32:44+00:00\",\"dateModified\":\"2025-05-20T08:32:44+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/38463.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/38463.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38463.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JAVAfx\u9879\u76ee\u603b\u7ed3 &amp;&amp; \u7b97\u6cd5\u9898\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JAVAfx\u9879\u76ee\u603b\u7ed3 &amp;&amp; \u7b97\u6cd5\u9898 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/38463.html","og_locale":"zh_CN","og_type":"article","og_title":"JAVAfx\u9879\u76ee\u603b\u7ed3 &amp;&amp; \u7b97\u6cd5\u9898 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb788\u6b21\uff0c\u70b9\u8d5e21\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u6280\u672f    | \u5728\u9879\u76ee\u4e2d\u7684\u5e94\u7528                           || IO\u6d41    | \u6587\u4ef6\u8bfb\u5199\u3001\u7f51\u7edc\u6570\u636e\u4f20\u8f93\u3001\u5bf9\u8c61\u5e8f\u5217           || \u591a\u7ebf\u7a0b  | \u5e76\u53d1\u5904\u7406\u5ba2\u6237\u7aef\u8bf7\u6c42\u4efb\u52a1\u6267\u884c           || \u6587\u4ef6\u5206\u7247 | \u5927\u6587\u4ef6\u7684\u4e0a\u4f20\u4e0e\u4e0b\u8f7d                       |","og_url":"https:\/\/www.wsisp.com\/helps\/38463.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-20T08:32:44+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520083242-682c3e2acb0c3.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"11 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/38463.html","url":"https:\/\/www.wsisp.com\/helps\/38463.html","name":"JAVAfx\u9879\u76ee\u603b\u7ed3 &amp;&amp; \u7b97\u6cd5\u9898 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-20T08:32:44+00:00","dateModified":"2025-05-20T08:32:44+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/38463.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/38463.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/38463.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"JAVAfx\u9879\u76ee\u603b\u7ed3 &amp;&amp; \u7b97\u6cd5\u9898"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/38463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=38463"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/38463\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/38458"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=38463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=38463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=38463"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=38463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}