非同期バックグラウンド処理
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
非同期処理は、永続処理と並んで、バックグラウンド処理の 2 つ目のコンポーネントです。永続的な処理と非同期処理はどちらもバックグラウンドで行われますが、結局のところ大きく異なります。
非同期処理とは:
- 瞬時に映し出される。
- アプリの再起動やデバイスの再起動後も保持する必要がない。
- メインスレッド外で行われるか、メインスレッドをブロックします。
これは、将来の実行をスケジュールでき、アプリの再起動やデバイスの再起動後もスケジュールを維持する永続的な処理とは対照的です。非同期処理の例として、HTTP リクエストをメインスレッドから送信し、到着時にのみ結果を返す場合が挙げられます。
Java と Kotlin
非同期処理の処理方法は、使用するアプリ アーキテクチャ全体によって異なります。Java プログラミング言語アプリを使用する場合のニーズは、Kotlin を使用する場合とは異なります。
|
Kotlin |
Java |
解決策 |
コルーチン。 |
Java スレッドです。 |
参考資料 |
コルーチンの詳細については、コルーチン ガイドをご覧ください。 |
詳細については、Java スレッドのページをご覧ください。 |
参考資料
永続処理の詳細については、永続処理の概要をご覧ください。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-26 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-26 UTC。"],[],[],null,["# Asynchronous background processing\n\nAsynchronous work is the second component of background work, alongside\npersistent work. While both persistent and asynchronous work take place in the\nbackground, they are ultimately quite different.\n\nAsynchronous work is that which:\n\n- Takes place in the moment.\n- Does not need to persist across app restarts or device reboots.\n- Occurs off the main thread, or blocks the main thread.\n\nThis is in contrast to persistent work, which you may schedule for future\nexecution and which remains scheduled through app restarts and device reboots.\nAn example of asynchronous work may be sending an HTTP request off the main\nthread, returning its result only when it arrives.\n\nJava and Kotlin\n---------------\n\nThe way you handle asynchronous work depends on the overall app architecture\nyou follow. If you are working with a Java Programming Language app, your needs\nare different than if you are working with Kotlin.\n\n| | Kotlin | Java |\n| Solution | Coroutines. | Java threads. |\n| Further reading | For a full overview of Coroutines, see the [Coroutines guide](/kotlin/coroutines). | See the [Java Threads](/guide/background/asynchronous/java-threads) page for more information. |\n|-----------------|------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|\n\nFurther reading\n---------------\n\nFor more information on persistent work, see the [persistent work overview](/guide/background/persistent)."]]