-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat : 예약 선점 로직 구현 #23
Changes from 1 commit
b586545
f3c8fc4
b40b419
c56bce6
67325fd
c34397d
bbf3e0e
edb3ab9
e414100
daa8856
6a8474d
125769f
bccd4f5
78e0c33
ac5d2a7
6512917
b4c47f9
0c4cc05
321bacd
826fb02
d454045
6308661
8cd163b
cf1de2d
f831d84
f20aa75
87bf03a
f05aea7
c0ff8f5
3e1f6c5
762e4f4
84a86fc
51fb95f
bc306d4
8b0c940
07b850d
9dca088
5c0d43a
ab7d66b
5e7e42d
b43c4fa
d64bdc7
51c0f2e
44e3c40
8eaf6ec
2898a36
bd8a90f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,26 @@ | ||
package com.prgrms.catchtable.reservation.service; | ||
|
||
import static org.springframework.transaction.annotation.Propagation.REQUIRES_NEW; | ||
|
||
import com.prgrms.catchtable.reservation.domain.ReservationTime; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.annotation.Async; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class ReservationAsync { | ||
|
||
@Async | ||
@Transactional(propagation = REQUIRES_NEW) | ||
@Transactional | ||
public void setPreOcuppied(ReservationTime reservationTime) { | ||
reservationTime.reversePreOccupied(); | ||
|
||
try { | ||
Thread.sleep(5_000); | ||
} catch (InterruptedException exception) { | ||
exception.printStackTrace(); | ||
} | ||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); | ||
scheduler.schedule(reservationTime::reversePreOccupied, 10, TimeUnit.SECONDS); | ||
Comment on lines
+19
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 정말 몰라서 여쭈는 건데, 쓰레드 1개를 더 할당해서 10분 뒤에 reversePreOccupied 메서드를 호출하는 건가요?.? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 쓰레드 1개를 더 할당해서 쓰는 스케줄러 맞습니다. 근데 여기서 설정된 시간인 10초동안 기다렸다가 스레드가 시간이 됐을 때 할당되어 작업이 실행되기 때문에 Thread.sleep()보다는 이걸 쓰는게 맞는 것 같습니다. |
||
|
||
reservationTime.reversePreOccupied(); | ||
scheduler.shutdown(); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
로그를 출력하는 부분이 없는 것 같아 해당 어노테이션이 없어도 될 것 같습니다!