commit ed64c2e6490ea049cbc804ad6435474f7b07040d Author: dingzhaojun Date: Fri Jan 19 07:17:14 2024 +0800 首次提交 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..94f480d --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4532bdd --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +# Build and Release Folders +target/ + +# Eclipse +.settings/ +*.classpath +*.project +*.factorypath + +# IntelliJ IDEA +.idea +*.iml + +# vscode +.vscode + +# JRebel +rebel.xml + +# macOS +.DS_Store + +# svn +.svn/ + +# vue +kernel-standard/ +node_modules/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..49b926e --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# spring-virtual-thread + +## Jmeter Test results : + +### Platform Thread +![Screenshot 2023-12-16 at 9 53 22 AM](https://github.com/Java-Techie-jt/spring-virtual-thread/assets/25712816/03978099-4df3-4686-a6e6-8eb1f28ab69f) + +### Virtual Thread +![Screenshot 2023-12-16 at 9 59 04 AM](https://github.com/Java-Techie-jt/spring-virtual-thread/assets/25712816/2f82ae30-41f3-4f29-a1de-10e6661840cf) diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..51dae93 --- /dev/null +++ b/pom.xml @@ -0,0 +1,69 @@ + + + 4.0.0 + net.risesoft + demo03 + 1.0 + demo03 + + + org.springframework.boot + spring-boot-starter-parent + 3.2.1 + + + + + 21 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-data-jpa + + + com.mysql + mysql-connector-j + runtime + + + org.apache.commons + commons-lang3 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/src/main/java/net/risesoft/demo/virtualthread/VtTestApplication.java b/src/main/java/net/risesoft/demo/virtualthread/VtTestApplication.java new file mode 100644 index 0000000..ccc5823 --- /dev/null +++ b/src/main/java/net/risesoft/demo/virtualthread/VtTestApplication.java @@ -0,0 +1,13 @@ +package net.risesoft.demo.virtualthread; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class VtTestApplication { + + public static void main(String[] args) { + SpringApplication.run(VtTestApplication.class, args); + } + +} diff --git a/src/main/java/net/risesoft/demo/virtualthread/controller/ProductController.java b/src/main/java/net/risesoft/demo/virtualthread/controller/ProductController.java new file mode 100644 index 0000000..a964d18 --- /dev/null +++ b/src/main/java/net/risesoft/demo/virtualthread/controller/ProductController.java @@ -0,0 +1,29 @@ +package net.risesoft.demo.virtualthread.controller; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import lombok.extern.slf4j.Slf4j; +import net.risesoft.demo.virtualthread.entity.Product; +import net.risesoft.demo.virtualthread.repository.ProductRepository; + +@RestController +@RequestMapping("/products") +@Slf4j +public class ProductController { + + @Autowired + private ProductRepository productRepository; + + @GetMapping + public List getProducts() throws InterruptedException { + Thread.sleep(1000); + log.info("Thread info {} ", Thread.currentThread()); + return productRepository.findAll(); + } + +} \ No newline at end of file diff --git a/src/main/java/net/risesoft/demo/virtualthread/entity/Product.java b/src/main/java/net/risesoft/demo/virtualthread/entity/Product.java new file mode 100644 index 0000000..4ab8831 --- /dev/null +++ b/src/main/java/net/risesoft/demo/virtualthread/entity/Product.java @@ -0,0 +1,15 @@ +package net.risesoft.demo.virtualthread.entity; + +import jakarta.persistence.*; +import lombok.Data; + +@Entity +@Data +@Table(name = "PRODUCT_TBLS") +public class Product { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String name; + private Long price; +} \ No newline at end of file diff --git a/src/main/java/net/risesoft/demo/virtualthread/repository/ProductRepository.java b/src/main/java/net/risesoft/demo/virtualthread/repository/ProductRepository.java new file mode 100644 index 0000000..901fc47 --- /dev/null +++ b/src/main/java/net/risesoft/demo/virtualthread/repository/ProductRepository.java @@ -0,0 +1,8 @@ +package net.risesoft.demo.virtualthread.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import net.risesoft.demo.virtualthread.entity.Product; + +public interface ProductRepository extends JpaRepository { +} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..37f4583 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,20 @@ +server: + port: 9191 +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/y9_public + username: root + password: '12345678' + jpa: + hibernate: + ddl-auto: update + naming: + physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl + properties: + hibernate: + dialect: org.hibernate.dialect.MySQLDialect + show-sql: true + threads: + virtual: + enabled: true diff --git a/src/test/java/com/javatechie/VtTestApplicationTests.java b/src/test/java/com/javatechie/VtTestApplicationTests.java new file mode 100644 index 0000000..78fca32 --- /dev/null +++ b/src/test/java/com/javatechie/VtTestApplicationTests.java @@ -0,0 +1,13 @@ +package com.javatechie; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class VtTestApplicationTests { + + @Test + void contextLoads() { + } + +}