A $i thread:${Thread.currentThread()}") } } launch { for (i in 1..5) { println("Hello B $i thread:${Thread.currentThread()}") } } launch { for (i in 1..5) { println("Hello C $i thread:${Thread.currentThread()}") } } }
3 thread:Thread[main,5,main] Hello A 4 thread:Thread[main,5,main] Hello A 5 thread:Thread[main,5,main] Hello B 1 thread:Thread[main,5,main] Hello B 2 thread:Thread[main,5,main] ・・・ Hello C 1 thread:Thread[main,5,main] Hello C 2 thread:Thread[main,5,main] ・・・ Aの1〜5→Bの1〜5→Cの1〜5 の順番で出力される
// 中断 println("Hello A $i thread:${Thread.currentThread()}") } } launch { for (i in 1..5) { delay(1) // 中断 println("Hello B $i thread:${Thread.currentThread()}") } } launch { for (i in 1..5) { delay(1) // 中断 println("Hello C $i thread:${Thread.currentThread()}") } } }
1 thread:Thread[main,5,main] Hello A 2 thread:Thread[main,5,main] Hello B 2 thread:Thread[main,5,main] Hello C 2 thread:Thread[main,5,main] Hello A 3 thread:Thread[main,5,main] Hello B 3 thread:Thread[main,5,main] ・・・ Aの1→Bの1→Cの1→Aの2→Bの2・・・ と出力される
@param id must not be null. * @return [Mono] emitting the entity with the given id or empty if none found. * @throws IllegalArgumentException in case the given id is null. */ suspend fun findById(id: ID): T? /** * Returns whether an entity with the given id exists. * * @param id must not be null. * @return true if an entity with the given id exists, false otherwise. * @throws IllegalArgumentException in case the given id is null. */ suspend fun existsById(id: ID): Boolean /** * Deletes the entity with the given id. * * @param id must not be null. * @throws IllegalArgumentException in case the given id is null. */ suspend fun deleteById(id: ID)
List<User> @Query( """ SELECT * FROM user ORDER BY age LIMIT 1 """ ) suspend fun findMostYoung(): User } • シンプルなクエリは、 findByNameなど機能とカラム名の命名規則で作れる • @Queryを使うことで自由にクエリを定義することもできる • これもノンブロッキングになる