Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
深いい勉強会 vol.9
Search
FujiKinaga
December 24, 2018
Programming
0
98
深いい勉強会 vol.9
FujiKinaga
December 24, 2018
Tweet
Share
More Decks by FujiKinaga
See All by FujiKinaga
最新のCompose Multiplatform を使うとiOSとAndroidアプリはどれくらい作れるのか
fujikinaga
2
570
Androidのテストの理解を深めてみた
fujikinaga
0
53
開発案件の進み方
fujikinaga
0
80
深いい勉強会 vol.10
fujikinaga
0
79
Understanding Dagger2 Part1
fujikinaga
0
40
Mater of Subscription
fujikinaga
0
61
深いい勉強会
fujikinaga
2
65
深いい勉強会 The Navigation Component
fujikinaga
0
52
深いい勉強会
fujikinaga
0
62
Other Decks in Programming
See All in Programming
Hotwire or React? ~Reactの録画機能をHotwireに置き換えて得られた知見~ / hotwire_or_react
harunatsujita
9
4.1k
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
23k
推し活の ハイトラフィックに立ち向かう Railsとアーキテクチャ - Kaigi on Rails 2024
falcon8823
6
2.2k
macOS でできる リアルタイム動画像処理
biacco42
7
1.9k
CSC509 Lecture 08
javiergs
PRO
0
110
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
3
400
go.mod、DockerfileやCI設定に分散しがちなGoのバージョンをまとめて管理する / Go Connect #3
arthur1
10
2.4k
Progressive Web Apps für Desktop und Mobile mit Angular (Hands-on)
christianliebel
PRO
0
110
Vaporモードを大規模サービスに最速導入して学びを共有する
kazukishimamoto
4
4.3k
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
550
Sidekiqで実現する 長時間非同期処理の中断と再開 / Pausing and Resuming Long-Running Asynchronous Jobs with Sidekiq
hypermkt
6
2.7k
カラム追加で増えるActiveRecordのメモリサイズ イメージできますか?
asayamakk
4
1.6k
Featured
See All Featured
Thoughts on Productivity
jonyablonski
67
4.3k
Why Our Code Smells
bkeepers
PRO
334
57k
Fontdeck: Realign not Redesign
paulrobertlloyd
81
5.2k
Code Review Best Practice
trishagee
64
17k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.2k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Typedesign – Prime Four
hannesfritz
39
2.4k
The Pragmatic Product Professional
lauravandoore
31
6.3k
The Power of CSS Pseudo Elements
geoffreycrofte
72
5.3k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Making the Leap to Tech Lead
cromwellryan
132
8.9k
Transcript
JavaͱAndroidͷεϨου ਂ͍͍ษڧձ
ͳΜ͔εϨουܥͷ࣮͍ͬͺ͍ݟͨ ͜ͱ͋Δͧɻɻɻ
ฉ͍ͨ͜ͱͷ͋ΔεϨουؔ࿈Ϋϥε • Handler • HandlerThread • ActivityThread • Runnable •
ExecutorService • ThreadPool • AsyncTask • AsyncTaskLoader • RxJava’s Schedulers • RxAndroid’s AndroidSchedulers • Coroutines
εϨουΛىಈ͢Δํ๏2छྨ͔͠ͳ͍ (JavaϚϧνεϨουϓϩάϥϛϯάॻΑΓ) • ThreadΫϥεͷαϒΫϥεͷΠϯελϯεΛ ͬͯεϨουΛىಈ͢Δ - SubClassThread().start() • RunnableΠϯλʔϑΣʔεͷ࣮ΫϥεͷΠ ϯελϯεΛͬͯεϨουΛىಈ͢Δ
- Thread(RunnableImpl()).start()
ͭ·Γ࣮࣭̍छྨ͔͠ͳ͍ʁ
ThreadΫϥεΛStartͯ͠ Runnable::run͕ݺΕΔͱ ৽͍͠εϨου͕ىಈ͢Δ
ͳΔ΄Ͳɻ
ࠓ·Ͱݟ͖ͯͨṖΫϥεͨͪ ཪͰThread().start()͍ͯ͠ Δʹҧ͍ͳ͍
• ThreadΫϥε - ࠷جຊతͳεϨουੜɾىಈͷΫϥε • RunnableΠϯλʔϑΣʔε - εϨου͕࣮ߦ͢ΔʮࣄʯΛද͢ΠϯλʔϑΣʔε • ThreadFactoryΠϯλʔϑΣʔε
- εϨουੜΛநԽͨ͠ΠϯλʔϑΣʔε • ExecutorΠϯλʔϑΣʔε - εϨουͷ࣮ߦΛநԽͨ͠ΠϯλʔϑΣʔε • ExecutorServiceΠϯλʔϑΣʔε - ࠶ར༻͞ΕΔεϨουͷ࣮ߦΛநԽͨ͠ΠϯλʔϑΣʔε • ScheduledExecutorServiceΠϯλʔϑΣʔε - εέδϡʔϦϯά͞ΕͨεϨουͷ࣮ߦΛநԽͨ͠ΠϯλʔϑΣʔε • ExecutorsΫϥε - ΠϯελϯεੜͷϢʔςΟϦςΟΫϥε
ThreadPool • WorkerThreadύλʔϯΛ༻͍ͨεϨουॲཧͷ͜ͱΛ BackgroundThreadͱݺͿ͜ͱ͋Γ·͢ɻ·ͨɺϫʔ ΧʔεϨουΛͨ͘͞Μอ͍࣋ͯ͠Δॴͷํʹ͠ ͯɺThreadPoolͱݺͿ͜ͱ͋Γ·͢ɻ • WorkerThreadύλʔϯͱɺෳͷεϨουΛ͋Β͔͡ Ί࡞ͯ͠ػ͓͖ͤͯ͞ɺλεΫ͕དྷͨΒ͍ͬͯΔ εϨουʹλεΫΛׂΓͯͯॲཧΛ։࢝ͤ͞ΔΈ
Handler • εϨουؒ௨৴ͷͨΊͷΈɻHandlerΠϯελϯ εΛੜͨ͠εϨουΠϕϯτΛૹΔͨΊͷΈ • Θ͔Γ͍͢ - http://d.hatena.ne.jp/sankumee/ 20120329/1333021847 -
https://academy.realm.io/jp/posts/android-thread- looper-handler/
JavaΫϥεΛAndroidͰ͍ ͍͢Α͏ʹͨ͠Ϋϥεͨͪ • HandlerThread - JavaͷThreadΛΑΓ؆୯ʹѻ͑ΔΑ͏ʹ ϥοϐϯάͨ͠ͷ • AsyncTask -
Thread·ͨMessage LoopͳͲͷಈ࡞ݪཧ Λख़͍ͯ͠ͳͯ͑͘Δ
ΈΛΒͳ͍ͷʹ͑ͪΌ ͏ͷා͍…
RxJava • SchedulersΠϯλʔϑΣʔεͷ͍ͣΕ͔Λࢦఆ͢Δͱɺ SchedulerͷαϒΫϥε͕ͦΕͧΕద༻͞Εɺͦͷ࣮ͷ தnameͱpriorityΛઃఆ͠ɺσʔϞϯεϨουԽ͠ ͨεϨουΛ࡞͢Δ࣮ʹͳ͍ͬͯͨ • Schedulersͷ߲͝ͱʹWorkerThreadΛ͍࣋ͨͤͯͨ ΓɺεϨουΛΩϟογϡͯ͠࠶ར༻͢ΔΑ͏ͳ࣮ʹ ͳ͍ͬͯͨΓͨ͠(.io,
.single, .computation, .newThread)
None
RxAndroid • AndroidSchedulers.mainThread()Handlerʹ MainLooperΛࢦఆͨ͠ΠϯελϯεΛ෦ͷΫϥε ʹઃఆ͍ͯ͠Δ • AndroidSchedulers.from(looper: Looper)Λ͑ର ͷLooperΛࢦఆͰ͖ΔͷͰɺRx௨৴࣌ʹҟͳΔε ϨουʹΠϕϯτΛૹΔ͜ͱՄೳΈ͍ͨ(Ϣʔεέʔ
ε͋Δʁ)
ϥεϘε Coroutines
What’s Coroutines • ʮಛఆͷεϨουʹଋറ͞Εͳ͍ɺதஅՄೳ ͳܭࢉॲཧΠϯελϯεʯ • ؔͷ్தͰதஅͰ͖ͨΓ࠶։ͨ͠ΓͰ͖Δ ͭ - http://sys1yagi.hatenablog.com/entry/
2017/06/13/001408
ʰಛఆͷεϨουʹଋറ͞Εͳ͍ʱ ˣ Coroutines༻ͷεϨουΛ࡞ͬͯΔͬ ͯ͜ͱʁ݁ہεϨουͰͷඇಉظॲ ཧʹมΘΓͳ͍ʁ
·͢·͢Θ͔Βͳ͍ɻ https://qiita.com/k-kagurazaka@github/items/ 8595ca60a5c8d31bbe37
࣍CoroutinesΛษڧ͢Δ(॓) • ཪͰεϨουΛىಈ͍ͯ͠Δͷ͔ - εϨουϓʔϧͷػೳΛ͍ͬͯΔΒ͍͠ • εϨουΑΓ͍ܰͷͳͥͳͷ͔ • தஅͷ࣮ʹഭΔ •
CoroutineContextͱ
·ͱΊ • HandlerεϨουΛىಈͯ͠ͳ͍ • Handler.postϝιουͷҙຯΛཧղͰ͖ͨ - εϨουͷΩϡʔʹ٧·ͬͨॲཧΛऴ͑ͨΒಈ͖ग़͢(Ͳ͜ ͷεϨουͰॲཧ͢Δ͔બΔ) • JavaͷεϨουΛཧղ্ͨ͠ͰAndroidʹ࠷దԽ͞ΕͨεϨο
υ༻ͷΧελϜΫϥεΛ͏ͱศར • CoroutinesԿऀ
Fin.