μ¬λ¬ κ°μ CPU μ½μ΄λ₯Ό νλμ μΉ©μ λ΄μ₯ν ꡬ쑰.
κ° μ½μ΄κ° λ
립μ μΌλ‘ λμ β λ³λ ¬ μ²λ¦¬ κ°λ₯.
πμ₯μ :
βμ£Όμν μ :
νλμ νλ‘μΈμ€μμ μ¬λ¬ μ€ν νλ¦(Thread)μ λ§λ€μ΄ λμμ±/λ³λ ¬μ± ꡬν
ExecutorService pool = Executors.newFixedThreadPool(μ½μ΄ μ);
pool.submit(() -> μμ
μν);
pool.shutdown();
| λ©μλ | μ€λͺ |
|---|---|
availableProcessors() | μ½μ΄ μ νμΈ |
Executors.newFixedThreadPool() | μ€λ λ ν μμ± |
.submit() | μμ λ±λ‘ |
.shutdown() | μμ μλ£ ν μ’ λ£ |
μ¬λ¬ μ€λ λκ° λμμ μμμ μ κ·Όν λ μ€λ₯ μμ΄ μμ νκ² λμνλλ‘ λ³΄μ₯νλ κΈ°λ².
| κΈ°λ² | μν | νΉμ§ |
|---|---|---|
synchronized | ν λ²μ ν μ€λ λλ§ μ κ·Ό νμ© | λ리μ§λ§ μμ |
volatile | λ³μ λ³κ²½ μ¦μ λͺ¨λ μ€λ λμ λ°μ | κ°μμ± λ³΄μ₯, μμμ±μ X |
| λμμ± μ»¬λ μ | λ³λ ¬ νκ²½μμλ μμ νκ² λμ | ConcurrentHashMap λ± |
λ©ν°μ½μ΄λ λ³λ ¬μ±, λ©ν°μ€λ λ©μ λμμ±μ κ°λ₯νκ² νκ³ , Javaμμλ μ€λ λ νκ³Ό λκΈ°ν κΈ°λ²μΌλ‘ μ΄λ₯Ό μμ μ μΌλ‘ μ μ΄ν μ μμ΅λλ€.
μμ‘΄μ±μΈν

π§ model.Author
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Author {
private Integer id;
private String name;
}
ποΈ repository.AuthorRepository
@Repository
public class AuthorRepository {
private final Map<Integer, Author> store = new LinkedHashMap<>();
private final AtomicInteger seq = new AtomicInteger(0);
public Author save(Author author) {
if (author.getId() == null) {
author.setId(seq.incrementAndGet());
}
store.put(author.getId(), author);
return author;
}
}
π§© service.AuthorService
@Service
@RequiredArgsConstructor
public class AuthorService {
private final AuthorRepository authorRepository;
public Author create(Author author) {
return authorRepository.save(author);
}
}
π dto.AuthorDto
@Getter
@Setter
public class AuthorDto {
private Integer id;
@NotBlank(message = "μ΄λ¦μ μ
λ ₯νμΈμ")
private String name;
}
π‘ controller.AuthorController
@RestController
@RequestMapping("/api/authors")
@RequiredArgsConstructor
public class AuthorController {
private final AuthorService authorService;
@PostMapping
public Author create(
@Valid @RequestBody AuthorDto authorDto
) {
Author author = Author.builder()
.name(authorDto.getName())
.build();
return authorService.create(author);
}
}
Postmanμ API κ°λ° λ° ν
μ€νΈλ₯Ό μ½κ² ν΄μ£Όλ GUI κΈ°λ° λꡬλ€.
νλ‘ νΈμλ, λ°±μλ κ°λ°μ λͺ¨λ RESTful APIλ₯Ό μμ²νκ³ μλ΅μ νμΈνκΈ° μν΄ λ§μ΄ μ¬μ©νλ€.
postman μ€μΉ

postmanμμ νμΈ


π Amazon Linux 2023 AMI λ²μ
# 1. μμ€ν
ν¨ν€μ§ μ΅μ ν
# 2. PostgreSQL 15 μ€μΉ (ν΄λΌμ΄μΈνΈ + μλ²)
# 3. λ°μ΄ν°λ² μ΄μ€ μ΄κΈ°ν
sudo dnf update -y
sudo dnf install -y postgresql15 postgresql15-server
sudo postgresql-setup --initdb
# 4. μλΉμ€ νμ±ν λ° μμ
# 5. μ€μΉ νμΈ
sudo systemctl start postgresql
sudo systemctl enable postgresql
sudo systemctl status postgresql
sudo dnf install git -y
git --version
sudo dnf install java-17-amazon-corretto -y
java --version
sudo -u postgres psql
postgresμ password μ€μ
ALTER USER postgres WITH PASSWORD '<SUPERUSER_PASSWORD>';
\q
π λΉλ°λ²νΈ μ λ ₯λ°©μ = md5λ‘ λͺ¨λ λ³κ²½
sudo nano /var/lib/pgsql/data/pg_hba.conf
<# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all md5
host replication all 0.0.0.0/0 md5
host replication all ::1/128 md5
(μ μ₯ : ctrl x y enter)
π μΈλΆ ν΄λΌμ΄μΈνΈ μ°κ²° νμ© μ€μ
sudo -u postgres psql -c "SHOW config_file";
# κ²½λ‘ νμΈ ν νΈμ§
sudo nano /var/lib/pgsql/data/postgresql.conf
# listen_addresses = 'localhost' β listen_addresses = '*'
ctrl w λ‘ localhostλ₯Ό κ²μ
Connection Settings
- listen_addresses = '*' # what IP address(es) to listen on;
(μ μ₯ : ctrl x y enter)
βοΈ ν μ΄λΈ μμ±
# λ³κ²½ μ μ© μ μ¬μμ
sudo systemctl restart postgresql
# λλ μ€μ λ§ μ¬λ‘λ κ°λ₯
sudo systemctl reload postgresql
psql -U postgres -W
Password:
psql (14.18)
Type "help" for help.
CREATE USER projectname WITH PASSWORD 'password';
CREATE DATABASE projectname OWNER projectname;
CREATE TABLE ...
intellijμμ git push μ μ jdbcνκ²½λ³μ/toolchain/jdkλ²μ μ€μ
βοΈ resources.application.yml
spring:
application:
name: to_do_list_with_dto
datasource:
url: jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
βοΈ rootfolder.settings.gradle
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}
}
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0"
}
rootProject.name = 'to_do_list_with_dto'
cat settings.gradle
βοΈ rootfolder.system.properties
java.runtime.version=17
μ€μ ν λ€ git push
aws linux μμ..
git clone your_github_repository_address
βοΈ aws amazon os environment variable
sudo nano ~/.bashrc
.bashrc νμΌ λ§¨ μλμ
βοΈ JDK νκ²½λ³μ μ€μ (νκ²½λ³μ νΈμ§μμ java_home, path μΆκ° κ°μ κΈ°λ₯)
export JAVA_HOME=/usr/lib/jvm/java-17-amazon-corretto
export PATH=$JAVA_HOME/bin:$PATH
βοΈ μ¬μ©μ νκ²½λ³μ μ€μ (μΈν 리μ μ΄ edit configuration μ€μ μν )
export APP_NAME=project_name
export DB_HOST=localhost
export DB_PORT=5432
export DB_NAME=project_name
export DB_USERNAME=project_name
export DB_PASSWORD=password
localhostλΆλΆμ db μλ²κ° λ€λ₯΄λ©΄ κ·Έ μλ²λ‘ λ€λ₯΄κ² μ€μ ν΄μ€μΌνλ€.
μ μ©
source ~/.bashrc
chmod +x gradlew
rm -rf ~/.gradle
./gradlew clean build
./gradlew clean build -x test
ls build/libs/
dashboard-0.0.1-SNAPSHOT.jar dashboard-0.0.1-SNAPSHOT-plain.jar
nohup java -jar build/libs/filename-0.0.1-SNAPSHOT.jar > log.txt 2>&1 &
tail -f log.txt
λλ €λ©΄
kill pid
sudo yum install cronie -y
crontab -e
-----crontab-----
i
* * * * * /sbin/shutdown -h now
:wq
-----------------
sudo systemctl start crond
sudo systemctl enable crond
β±οΈ ν¬λ‘ ν νμ
λΆ μ μΌ μ μμΌ <μ€νν λͺ
λ Ή>
* * * * * /sbin/shutdown -h now
| νλ μμΉ | μλ―Έ | μμ κ° | μ€λͺ |
|---|---|---|---|
| 1 | λΆ(minute) | 0β59 | λ§€ μκ°μ λͺ λΆμ μ€νν μ§ |
| 2 | μ(hour) | 0β23 | ν루 μ€ λͺ μμ μ€νν μ§ (0 = μμ ) |
| 3 | μΌ(day of month) | 1β31 | λ§€λ¬ λ©°μΉ μ μ€νν μ§ |
| 4 | μ(month) | 1β12 | λͺ μμ μ€νν μ§ |
| 5 | μμΌ(day of week) | 0β7 | 0 λλ 7 = μΌμμΌ, 1 = μμμΌ ... 6 = ν μμΌ |