Async และ Scheduling
การทำงานแบบ asynchronous ด้วย @Async, การ scheduling ด้วย @Scheduled, ThreadPoolTaskExecutor, การจัดการเวลา
1annotation ใดที่ทำให้ method ทำงานแบบ asynchronous ใน Spring?
annotation ใดที่ทำให้ method ทำงานแบบ asynchronous ใน Spring?
คำตอบ
@Async ทำเครื่องหมาย method สำหรับการทำงานแบบ asynchronous Spring จะรัน method นี้ใน thread แยกต่างหากผ่าน TaskExecutor ต้องมี @EnableAsync บนคลาส configuration เพื่อเปิดใช้งานกลไกนี้ มีประโยชน์สำหรับการทำงานที่ใช้เวลานาน (ส่งอีเมล, ประมวลผลไฟล์) โดยไม่บล็อก thread หลัก method สามารถคืนค่า void, Future หรือ CompletableFuture ได้
2annotation ใดที่เปิดใช้งานการรองรับ method @Async ใน Spring?
annotation ใดที่เปิดใช้งานการรองรับ method @Async ใน Spring?
คำตอบ
@EnableAsync เปิดใช้งานการประมวลผล annotation @Async ต้องวางไว้บนคลาส @Configuration หากไม่มี annotation นี้ @Async จะถูกละเลยและ method จะทำงานแบบ synchronous
3return type แบบ legacy ใดที่ช่วยให้ดึงผลลัพธ์ของ method @Async ได้?
return type แบบ legacy ใดที่ช่วยให้ดึงผลลัพธ์ของ method @Async ได้?
คำตอบ
Future<T> เป็น return type ดั้งเดิมสำหรับ method แบบ asynchronous ช่วยให้ดึงผลลัพธ์ผ่าน future.get() (แบบบล็อก) ปัจจุบันนิยมใช้ CompletableFuture<T> มากกว่าเพราะรองรับการเขียนโปรแกรมเชิงฟังก์ชันและการประกอบที่ดีกว่า
ข้อได้เปรียบหลักของ CompletableFuture เหนือ Future สำหรับ method @Async คืออะไร?
AsyncResult ใช้สำหรับอะไรใน Spring?
+22 คำถามสัมภาษณ์
หัวข้อสัมภาษณ์ Spring Boot อื่นๆ
Spring Core - IoC & DI
Spring Boot Auto-Configuration
Spring Boot Starters
Application Properties & YAML
การทำ Logging ด้วย SLF4J และ Logback
Spring Boot DevTools
Spring MVC Basics
Spring REST Controllers
Request & Response Handling
การจัดการข้อยกเว้น
Bean Validation
พื้นฐาน Spring Data JPA
เอนทิตี JPA และความสัมพันธ์
การสืบค้น JPA
Spring Data Repositories
พื้นฐาน Spring Security
Spring Boot Actuator
การทดสอบหน่วยด้วย JUnit และ Mockito
การทดสอบ Spring Boot
Profiles และ Environment
RestTemplate และ WebClient
Caching ด้วย Spring
Spring WebFlux (Reactive)
ทรานแซกชัน Spring
การยืนยันตัวตนและการให้สิทธิ์ขั้นสูง
JWT และความปลอดภัยแบบ Stateless
OAuth2 และ Authorization Server
Spring Boot และ Docker
Microservices ด้วย Spring
Spring Cloud Config
การเพิ่มประสิทธิภาพการทำงาน
GraalVM Native Images
เชี่ยวชาญ Spring Boot สำหรับการสัมภาษณ์ครั้งถัดไป
เข้าถึงคำถามทั้งหมด flashcards แบบทดสอบเทคนิค แบบฝึกหัด code review และตัวจำลองสัมภาษณ์
เริ่มใช้ฟรี