# id-generator **Repository Path**: saintlee/id-generator ## Basic Information - **Project Name**: id-generator - **Description**: No description available - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2018-07-12 - **Last Updated**: 2024-04-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README IdGenerator ID生成器 --- 使用spring data redis生成自增ID。使用方式如下: ```java @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest public class ApplicationTest { @Autowired OrderIdGenerator orderIdGenerator; @Autowired UserIdGenerator userIdGenerator; @Test public void testName1() throws Exception { for (int i = 0; i < 333; i++) { long id = userIdGenerator.next(); System.out.println(id); } } @Test public void testName2() throws Exception { ExecutorService executorService = Executors.newCachedThreadPool(); final Semaphore semaphore = new Semaphore(500); final CountDownLatch countDownLatch = new CountDownLatch(10000); for (int i = 0; i < 10000; i++) { executorService.execute(new Runnable() { @Override public void run() { try { semaphore.acquire(); generate(); semaphore.release(); } catch (InterruptedException e) { e.printStackTrace(); } countDownLatch.countDown(); } }); } countDownLatch.await(); executorService.shutdown(); } private void generate() { long id = orderIdGenerator.nextResetDay(); System.out.println(id); } } ```