Skip to content

Commit 2b8f45d

Browse files
committed
snow-flake-id-generator
1 parent d324cab commit 2b8f45d

File tree

5 files changed

+112
-0
lines changed

5 files changed

+112
-0
lines changed

snow-flake-id-generator/pom.xml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>springcloud</artifactId>
7+
<groupId>com.zcprog.springcloud</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>snow-flake-id-generator</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.springframework.boot</groupId>
17+
<artifactId>spring-boot-starter-web</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>cn.hutool</groupId>
21+
<artifactId>hutool-all</artifactId>
22+
<version>4.6.3</version>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.projectlombok</groupId>
26+
<artifactId>lombok</artifactId>
27+
<optional>true</optional>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-starter-test</artifactId>
32+
<scope>test</scope>
33+
</dependency>
34+
</dependencies>
35+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.zcprog.boot;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
/**
7+
* @Description 主启动类
8+
* @Author zhaochao
9+
* @Date 2021/1/19 9:49
10+
11+
* @Version V1.0
12+
*/
13+
@SpringBootApplication
14+
public class MainApp {
15+
public static void main(String[] args) {
16+
SpringApplication.run(MainApp.class, args);
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.zcprog.boot.controller;
2+
3+
import com.zcprog.boot.service.OrderService;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
/**
9+
* @Description 控制器
10+
* @Author zhaochao
11+
* @Date 2021/1/19 9:48
12+
13+
* @Version V1.0
14+
*/
15+
@RestController
16+
public class OrderController {
17+
18+
@Autowired
19+
private OrderService orderService;
20+
21+
@RequestMapping(("/snowflake"))
22+
public String index(){
23+
return orderService.getIdBySnowFlake();
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.zcprog.boot.service;
2+
3+
import com.zcprog.boot.util.IdGeneratorSnowflake;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.stereotype.Service;
6+
7+
import java.util.concurrent.ExecutorService;
8+
import java.util.concurrent.Executors;
9+
10+
/**
11+
* @Description 服务类
12+
* @Author zhaochao
13+
* @Date 2021/1/19 9:48
14+
15+
* @Version V1.0
16+
*/
17+
@Service
18+
public class OrderService {
19+
@Autowired
20+
private IdGeneratorSnowflake idGenerator;
21+
22+
public String getIdBySnowFlake() {
23+
ExecutorService threadPool = Executors.newFixedThreadPool(5);
24+
for (int i = 1; i <= 20; i++) {
25+
threadPool.submit(()->{
26+
System.out.println(idGenerator.snowflakeId());
27+
});
28+
}
29+
threadPool.shutdown();
30+
return "hello snowflake";
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
server:
2+
port: 7777

0 commit comments

Comments
 (0)