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
580
Androidのテストの理解を深めてみた
fujikinaga
0
53
開発案件の進み方
fujikinaga
0
81
深いい勉強会 vol.10
fujikinaga
0
79
Understanding Dagger2 Part1
fujikinaga
0
40
Mater of Subscription
fujikinaga
0
61
深いい勉強会
fujikinaga
2
67
深いい勉強会 The Navigation Component
fujikinaga
0
52
深いい勉強会
fujikinaga
0
62
Other Decks in Programming
See All in Programming
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
180
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
230
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
CSC509 Lecture 13
javiergs
PRO
0
110
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
100
C++でシェーダを書く
fadis
6
4.1k
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
230
RubyLSPのマルチバイト文字対応
notfounds
0
120
Outline View in SwiftUI
1024jp
1
330
Arm移行タイムアタック
qnighy
0
330
Featured
See All Featured
Agile that works and the tools we love
rasmusluckow
327
21k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
How GitHub (no longer) Works
holman
310
140k
BBQ
matthewcrist
85
9.3k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
The Language of Interfaces
destraynor
154
24k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Done Done
chrislema
181
16k
Become a Pro
speakerdeck
PRO
25
5k
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.