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
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
910
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
5
1.2k
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
410
103 Early Hints
sugi_0000
1
230
42 best practices for Symfony, a decade later
tucksaun
1
180
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
3
360
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
460
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
330
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.6k
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
280
命名をリントする
chiroruxx
1
410
Spatial Rendering for Apple Vision Pro
warrenm
0
110
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Raft: Consensus for Rubyists
vanstee
137
6.7k
Documentation Writing (for coders)
carmenintech
66
4.5k
Typedesign – Prime Four
hannesfritz
40
2.4k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Side Projects
sachag
452
42k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Thoughts on Productivity
jonyablonski
67
4.4k
Facilitating Awesome Meetings
lara
50
6.1k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
0
98
YesSQL, Process and Tooling at Scale
rocio
169
14k
The Art of Programming - Codeland 2020
erikaheidi
53
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.