Browse Source

update smart-servlet to 1.4 (#9081)

* update smart-servlet to 0.1.3-SNAPSHOT

* update aio-enhance to 1.0.3-SNAPSHOT

* smart-servlet bugfix

* bugfix

* update smart-socket to 1.5.6-SNAPSHOT

* remove file

* update aio-enhance to 1.0.4-SNAPSHOT

* 优化代码

* 优化代码

* update smart-socket to 1.5.6

* config threadNum

* update smart-socket to 1.5.7-SNAPSHOT

* 优化代码

* update smart-socket to 1.5.10-SNAPSHOT

* 优化代码

* 优化代码

* 优化代码

* 异常aio-enhance

* 优化代码

* 优化代码

* 优化代码

* remove aio-pro

* remove headerLimiter

* update hikaricp version

* replace json util

* 更新线程模型

* upgrade smart-servlet to 0.1.9-SNAPSHOT

* config thread num

* config thread num

* revert code

* revert code

* upgrade smart-servlet to 0.2.1-SNAPSHOT

* upgrade smart-servlet to 0.6-SNAPSHOT

* upgrade smart-servlet to 0.6-SNAPSHOT

* upgrade smart-servlet to 0.6-SNAPSHOT

* upgrade smart-servlet to 0.6-SNAPSHOT

* upgrade smart-servlet to 0.6-SNAPSHOT

* upgrade smart-servlet to 0.6-SNAPSHOT

* upgrade smart-servlet to 0.6-SNAPSHOT

* upgrade smart-servlet to 1.0-SNAPSHOT

* upgrade smart-servlet to 1.4

* upgrade smart-servlet to 1.5-SNAPSHOT

* 启用虚拟线程

* 启用虚拟线程
三刀 1 year ago
parent
commit
3670cf1211

+ 3 - 3
frameworks/Java/smart-socket/pom.xml

@@ -8,10 +8,10 @@
     <packaging>jar</packaging>
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <maven.compiler.source>17</maven.compiler.source>
-        <maven.compiler.target>17</maven.compiler.target>
+        <maven.compiler.source>21</maven.compiler.source>
+        <maven.compiler.target>21</maven.compiler.target>
         <log4j.version>2.17.1</log4j.version>
-        <smartservlet.version>1.0-SNAPSHOT</smartservlet.version>
+        <smartservlet.version>1.5-SNAPSHOT</smartservlet.version>
         <hikaricp.version>5.0.0</hikaricp.version>
         <jsoniter.version>0.9.23</jsoniter.version>
     </properties>

+ 1 - 1
frameworks/Java/smart-socket/smart-socket-smart-servlet.dockerfile

@@ -1,4 +1,4 @@
-FROM maven:3.8.6-openjdk-18-slim as maven
+FROM maven:3.9.7-amazoncorretto-21 as maven
 WORKDIR /smart-socket
 COPY pom.xml pom.xml
 COPY src src

+ 1 - 1
frameworks/Java/smart-socket/smart-socket.dockerfile

@@ -1,4 +1,4 @@
-FROM maven:3.8.6-openjdk-18-slim as maven
+FROM maven:3.9.7-amazoncorretto-21 as maven
 WORKDIR /smart-socket
 COPY pom.xml pom.xml
 COPY src src

+ 1 - 0
frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java

@@ -51,6 +51,7 @@ public class Bootstrap {
         HttpBootstrap bootstrap = new HttpBootstrap();
         bootstrap.configuration()
                 .threadNum(cpuNum)
+                .headerLimiter(0)
                 .readBufferSize(1024 * 4)
                 .writeBufferSize(1024 * 4)
                 .readMemoryPool(16384 * 1024 * 4)

+ 28 - 20
frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java

@@ -11,6 +11,7 @@ import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ThreadLocalRandom;
 
 /**
@@ -25,28 +26,35 @@ public class MultipleQueriesHandler extends HttpServerHandler {
     }
 
     @Override
-    public void handle(HttpRequest httpRequest, HttpResponse response) throws IOException {
-        int queries = Math.min(Math.max(NumberUtils.toInt(httpRequest.getParameter("queries"), 1), 1), 500);
-        World[] worlds = new World[queries];
-        try (Connection connection = dataSource.getConnection();
-             PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) {
-
-            for (int i = 0; i < queries; i++) {
-                preparedStatement.setInt(1, getRandomNumber());
-                ResultSet resultSet = preparedStatement.executeQuery();
-                resultSet.next();
-                World world = new World();
-                world.setId(resultSet.getInt(1));
-                world.setRandomNumber(resultSet.getInt(2));
-                worlds[i] = world;
-                preparedStatement.clearParameters();
+    public void handle(HttpRequest httpRequest, HttpResponse response, CompletableFuture<Object> completableFuture) throws IOException {
+        Thread.startVirtualThread(() -> {
+            try {
+                int queries = Math.min(Math.max(NumberUtils.toInt(httpRequest.getParameter("queries"), 1), 1), 500);
+                World[] worlds = new World[queries];
+                try (Connection connection = dataSource.getConnection();
+                     PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) {
+
+                    for (int i = 0; i < queries; i++) {
+                        preparedStatement.setInt(1, getRandomNumber());
+                        ResultSet resultSet = preparedStatement.executeQuery();
+                        resultSet.next();
+                        World world = new World();
+                        world.setId(resultSet.getInt(1));
+                        world.setRandomNumber(resultSet.getInt(2));
+                        worlds[i] = world;
+                        preparedStatement.clearParameters();
+                    }
+
+                } catch (SQLException throwables) {
+                    throwables.printStackTrace();
+                }
+                response.setContentType("application/json");
+                JsonUtil.writeJsonBytes(response, worlds);
+            } finally {
+                completableFuture.complete(null);
             }
+        });
 
-        } catch (SQLException throwables) {
-            throwables.printStackTrace();
-        }
-        response.setContentType("application/json");
-        JsonUtil.writeJsonBytes(response, worlds);
     }
 
     protected int getRandomNumber() {

+ 21 - 14
frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java

@@ -10,6 +10,7 @@ import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ThreadLocalRandom;
 
 /**
@@ -24,20 +25,26 @@ public class SingleQueryHandler extends HttpServerHandler {
     }
 
     @Override
-    public void handle(HttpRequest httpRequest, HttpResponse response) throws IOException {
-        World world = new World();
-        try (Connection connection = dataSource.getConnection();
-             PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) {
-            preparedStatement.setInt(1, getRandomNumber());
-            ResultSet resultSet = preparedStatement.executeQuery();
-            resultSet.next();
-            world.setId(resultSet.getInt(1));
-            world.setRandomNumber(resultSet.getInt(2));
-        } catch (SQLException throwables) {
-            throwables.printStackTrace();
-        }
-        response.setContentType("application/json");
-        JsonUtil.writeJsonBytes(response, world);
+    public void handle(HttpRequest httpRequest, HttpResponse response, CompletableFuture<Object> completableFuture) throws IOException {
+        Thread.startVirtualThread(() -> {
+            try {
+                World world = new World();
+                try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) {
+                    preparedStatement.setInt(1, getRandomNumber());
+                    ResultSet resultSet = preparedStatement.executeQuery();
+                    resultSet.next();
+                    world.setId(resultSet.getInt(1));
+                    world.setRandomNumber(resultSet.getInt(2));
+                } catch (SQLException throwables) {
+                    throwables.printStackTrace();
+                }
+                response.setContentType("application/json");
+                JsonUtil.writeJsonBytes(response, world);
+            } finally {
+                completableFuture.complete(null);
+            }
+        });
+
     }
 
     protected int getRandomNumber() {

+ 5 - 1
frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java

@@ -17,7 +17,10 @@ public class Bootstrap {
     public static void main(String[] args) throws Throwable {
         ContainerRuntime containerRuntime = new ContainerRuntime();
         // plaintext
-        ServletContextRuntime applicationRuntime = new ServletContextRuntime("/");
+        ServletContextRuntime applicationRuntime = new ServletContextRuntime(null, Thread.currentThread().getContextClassLoader(), "/");
+        applicationRuntime.setVendorProvider(response -> {
+
+        });
         ServletInfo plainTextServletInfo = new ServletInfo();
         plainTextServletInfo.setServletName("plaintext");
         plainTextServletInfo.setServletClass(HelloWorldServlet.class.getName());
@@ -38,6 +41,7 @@ public class Bootstrap {
         bootstrap.configuration()
                 .threadNum(cpuNum)
                 .bannerEnabled(false)
+                .headerLimiter(0)
                 .readBufferSize(1024 * 4)
                 .writeBufferSize(1024 * 4)
                 .readMemoryPool(16384 * 1024 * 4)