Created
March 18, 2020 05:14
-
-
Save swarawan/12f196c83fde00e0509cc7c53696c8f4 to your computer and use it in GitHub Desktop.
Multithread in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BookAgent(private val bookService: BookService) : Thread() { | |
override fun run() { | |
val uuid = UUID.randomUUID().toString() | |
for (n in 0..10) { | |
sleep(5000) | |
bookService.save( | |
BookDataRequestModel( | |
name = "Book $uuid version: $n", | |
excerpt = "excerpt", | |
content = "content", | |
author = "author", | |
publisher = "publisher" | |
) | |
) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@RequestMapping(value = ["/book"]) | |
class BookDataController : BaseController() { | |
@Autowired | |
lateinit var bookService: BookService | |
@PostMapping(value = ["thread"]) | |
@Transactional(rollbackFor = [Exception::class]) | |
fun addUsingThread(): ResponseEntity<ResultResponse> { | |
BookAgent(bookService).start() | |
return generateResponse(true).build() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment