일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- Docker
- git
- Source
- 문서
- Core Java
- jpa
- maven
- Tomcat
- Eclipse
- spring
- JavaScript
- AJAX
- STS
- 오픈소스
- SpringBoot
- 설정
- Python
- myBatis
- Thymeleaf
- MySQL
- oracle
- error
- Exception
- IntelliJ
- Open Source
- PostgreSQL
- JDBC
- MSSQL
- Spring Boot
- ubuntu
- Today
- Total
헤르메스 LIFE
[Spring Boot] JPA 동시 입력 테스트 본문
테스트 환경
https://hermeslog.tistory.com/568?category=1078420
MultiThreadMemberSaveTest.java
package com.study.springboot.system.repository;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.study.springboot.system.entity.Member;
@RunWith(SpringRunner.class)
@SpringBootTest
// @DataJpaTest
public class MultiThreadMemberSaveTest {
@Autowired(required = true)
MemberRepository memberRepository;
@Test
// @Rollback(false)
public void field() throws Exception {
System.out.println("main start .......");
for (int i = 0; i < 100; i++) {
Runnable task = new Task1();
Thread thread = new Thread(task);
thread.setName("thread-A" + i);
thread.start();
}
for (int i = 0; i < 100; i++) {
Runnable task = new Task2();
Thread thread = new Thread(task);
thread.setName("thread-B" + i);
thread.start();
}
for (int i = 0; i < 100; i++) {
Runnable task = new Task3();
Thread thread = new Thread(task);
thread.setName("thread-C" + i);
thread.start();
}
Thread.sleep(10000); // 재우지 않으면 Connection 이 Close 되어버림.
System.out.println("main exit .......");
}
class Task1 implements Runnable {
@Override
public void run() {
Member member = new Member("memberA", "");
member = memberRepository.save(member);
System.out.println(Thread.currentThread() + " >> " + member.toString());
}
}
class Task2 implements Runnable {
@Override
public void run() {
Member member = new Member("memberB", "");
member = memberRepository.save(member);
System.out.println(Thread.currentThread() + " >> " + member.toString());
}
}
class Task3 implements Runnable {
@Override
public void run() {
Member member = new Member("memberC", "");
member = memberRepository.save(member);
System.out.println(Thread.currentThread() + " >> " + member.toString());
}
}
}
Test 결과
springboot=# select *
from member;
id | password | username
------+----------+----------
1605 | | memberA
1614 | | memberB
1613 | | memberB
1609 | | memberB
1608 | | memberA
1611 | | memberA
1610 | | memberB
1612 | | memberA
1619 | | memberA
1615 | | memberB
1617 | | memberA
1620 | | memberA
1621 | | memberC
1622 | | memberB
1623 | | memberB
1624 | | memberA
1625 | | memberA
1628 | | memberB
1626 | | memberB
1630 | | memberA
1632 | | memberA
1634 | | memberC
1631 | | memberB
1633 | | memberA
1636 | | memberC
1635 | | memberB
1637 | | memberC
1640 | | memberA
1641 | | memberA
1643 | | memberA
1642 | | memberB
1644 | | memberC
1646 | | memberA
1647 | | memberC
1649 | | memberA
1650 | | memberB
............................
springboot=# select count(1) from member;
count
-------
300
(1 row)
JPA 는 동시 입력시 Lock 이 잘 걸리지 않는 모양입니다. ^^
만족스러운 테스트 결과 였습니다.
'Spring Boot Framework' 카테고리의 다른 글
[Spring Boot] 정적 페이지 로딩 (0) | 2022.02.27 |
---|---|
[Spring Boot] Multi FileUpload Test (0) | 2022.02.27 |
Common Application Properties (0) | 2022.02.27 |
[Spring Boot] Multi FileUpload (0) | 2022.02.27 |
[SpringBoot] Spring Boot에서 JSP 사용 (0) | 2022.02.26 |