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
590
Androidのテストの理解を深めてみた
fujikinaga
0
54
開発案件の進み方
fujikinaga
0
83
深いい勉強会 vol.10
fujikinaga
0
79
Understanding Dagger2 Part1
fujikinaga
0
41
Mater of Subscription
fujikinaga
0
61
深いい勉強会
fujikinaga
2
67
深いい勉強会 The Navigation Component
fujikinaga
0
52
深いい勉強会
fujikinaga
0
65
Other Decks in Programming
See All in Programming
Exploring: Partial and Independent Composables
blackbracken
0
100
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
テストコード書いてみませんか?
onopon
2
130
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
340
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
390
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
460
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
190
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
3
480
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
103 Early Hints
sugi_0000
1
230
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
5
660
Featured
See All Featured
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
Side Projects
sachag
452
42k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
A better future with KSS
kneath
238
17k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
GitHub's CSS Performance
jonrohan
1030
460k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
520
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Faster Mobile Websites
deanohume
305
30k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
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.