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
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
Amazon Qを使ってIaCを触ろう!
maruto
0
400
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
Macとオーディオ再生 2024/11/02
yusukeito
0
370
Jakarta EE meets AI
ivargrimstad
0
610
CSC509 Lecture 11
javiergs
PRO
0
180
Ethereum_.pdf
nekomatu
0
460
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
220
Outline View in SwiftUI
1024jp
1
330
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
Featured
See All Featured
Designing for humans not robots
tammielis
250
25k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Navigating Team Friction
lara
183
14k
Faster Mobile Websites
deanohume
305
30k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Making Projects Easy
brettharned
115
5.9k
Designing for Performance
lara
604
68k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
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.