{"id":336589,"date":"2022-08-05T03:00:05","date_gmt":"2022-08-05T03:00:05","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=336589"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=336589","title":{"rendered":"<span>\u041c\u0430\u0433\u0438\u044f Dispatcher&#8217;\u043e\u0432 \u0438 \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u043e\u0439 Main<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u042f \u0434\u0443\u043c\u0430\u044e \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0435 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043b\u044e\u0434\u0435\u0439, \u043d\u0435\u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0445 \u0441 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438 \u0432 Kotlin. \u0412\u043e\u043b\u0448\u0435\u0431\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u044b? \u0415\u0449\u0451 \u0431\u043e\u043b\u0435\u0435 \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u044b\u043c \u0432 \u043d\u0438\u0445 \u044f \u043d\u0430\u0445\u043e\u0436\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0442\u043e\u043a:<\/p>\n<pre><code class=\"kotlin\">fun main() = runBlocking { println(\"Hello from ${Thread.currentThread().name}\")   withContext(Dispatchers.Default) {     println(\"Hello from ${Thread.currentThread().name}\") }  println(\"Welcome back to ${Thread.currentThread().name}\") }  \/\/ \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: \/\/ Hello from main \/\/ Hello from DefaultDispatcher-worker-2 \/\/ Welcome back to main <\/code><\/pre>\n<p>\u0412\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u0438 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442 \u0438\u0437 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430. \u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u044d\u0442\u043e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c? \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0434\u043e \u0431\u043e\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e, \u0435\u0441\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <code>CoroutineDispatcher<\/code>, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0442\u0430\u043c \u0434\u0432\u0430 \u0432\u0430\u0436\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<pre><code class=\"kotlin\">public open fun isDispatchNeeded(context: CoroutineContext): Boolean = true public abstract fun dispatch(context: CoroutineContext, block: Runnable)<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u0430 <code>dispatch<\/code>, \u0430 \u0432\u043e\u0442 \u0432\u0442\u043e\u0440\u043e\u0439 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435, \u043e\u043d \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0432 <code>block<\/code> <code>Runnable<\/code> \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435. \u0421\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e <code>dispatch<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 <code>block<\/code><em>, <\/em>\u0438\u043d\u0430\u0447\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u043b\u043e\u0432\u0438\u0442\u044c <em>deadlock<\/em> \u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 <strong>\u043d\u0438\u043a\u043e\u0433\u0434\u0430 <\/strong>\u043d\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u0442\u0430\u043a \u0436\u0435 \u043c\u0435\u0442\u043e\u0434 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d <strong>\u043d\u0435 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043e<\/strong> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c <code>block<\/code>, \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u043f\u043e\u0442\u043e\u043a\u0435 \u043b\u0443\u0447\u0448\u0435 \u0432\u0435\u0440\u043d\u0443\u0442\u044c <code>false<\/code><em> <\/em>\u0438\u0437 <code>isDispatchNeeded<\/code>.<\/p>\n<h3>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442?<\/h3>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c 4 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0434\u0438\u0441\u043f\u0430\u0442\u0435\u0440\u0430, \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Dispatchers<\/code>: Default, Unconfined, Main, IO. <\/p>\n<p><strong>Unconfined: <\/strong>\u0421\u0430\u043c\u044b\u043c \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0438\u0437 \u043d\u0438\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>Unconfined<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u0442\u043e\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438 \u043a\u043e\u0434 \u0438\u0437 \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0442\u0430\u0442\u044c\u0438 \u0443\u0436\u0435 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c:<\/p>\n<pre><code class=\"kotlin\">runBlocking(Dispatchers.Unconfined) { println(\"Hello from ${Thread.currentThread().name}\") withContext(Dispatchers.Default) {     println(\"Hello from ${Thread.currentThread().name}\") }  println(\"Welcome back to ${Thread.currentThread().name}\") }  \/\/ \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: \/\/ Hello from main \/\/ Hello from DefaultDispatcher-worker-2 \/\/ Welcome back to DefaultDispatcher-worker-2)<\/code><\/pre>\n<p>\u0414\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u0437\u0430 \u0441\u0447\u0435\u0442 <code>isDispatchNeeded<\/code><em> <\/em>\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0435\u0447\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>false<\/code><em> <\/em>\u0438 \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 <code>dispatch<\/code>(\u0421\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e\u0441\u0442\u0438 \u0440\u0430\u0434\u0438 \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e <code>dispatch<\/code><em> <\/em>\u0432\u0441\u0451 \u0442\u0430\u043a\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u043d \u0438\u0437 <code>yield(),<\/code> \u043d\u043e \u044d\u0442\u043e \u0443\u0436\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u0430\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f).<\/p>\n<p><strong>Default, IO: <\/strong>\u042d\u0442\u0438 \u0434\u0432\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 <code>ExecutorCoroutineDispatcher<\/code><em> <\/em>\u0441 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0432 \u0432\u0438\u0434\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0432\u043e\u0435\u0433\u043e <code>Executor'\u0430<\/code>, Default \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442 <code>SchedulerCoroutineDispatcher<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044f \u0438\u0445 \u0432 <code>CoroutineScheduler<\/code>, \u044d\u0442\u043e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 <code>Executor<\/code>, \u0441 \u043f\u0443\u043b\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0440\u0430\u0432\u043d\u043e\u043c\u0443 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430(\u043c\u0438\u043d\u0438\u043c\u0443\u043c 2) \u0434\u043b\u044f CPU-bound \u0437\u0430\u0434\u0430\u0447, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c\u0441\u044f \u0434\u043e <em>maxPoolSize<\/em>, \u0440\u0430\u0432\u043d\u044b\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u043c\u0443 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0443 <em>kotlinx.coroutines.scheduler.max.pool.size<\/em>, \u0438\u043b\u0438 <em>2097150 <\/em>\u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c, \u0434\u043b\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u0437\u0430\u0434\u0430\u0447(IO). IO Dispatcher \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0447\u0435\u0440\u0435\u0437 Default \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044f \u0441\u0435\u0431\u044f \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u0440\u0430\u0432\u043d\u044b\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u043c\u0443 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0443 <em>kotlinx.coroutines.io.parallelism <\/em>\u0438\u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430(\u043c\u0438\u043d\u0438\u043c\u0443\u043c 64)). <code>CoroutineScheduler<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0438\u043b\u0438 \u043d\u0435\u0442 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>dispatchWithContext<\/code><em> <\/em>\u0443 <code>SchedulerCoroutineDispatcher<\/code><em>, <\/em>\u0433\u0434\u0435 \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0438\u043f \u0437\u0430\u0434\u0430\u0447\u0438: <code>BlockingContext<\/code><em> <\/em>\u0438\u0437 <em>IO<\/em> \u0438 <em>NonBlocking <\/em>\u0434\u043b\u044f \u043b\u044e\u0431\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0438\u0437 <code>Default<\/code><em>.<\/em><\/p>\n<p><strong>Main<\/strong>: \u0422\u043e, \u0440\u0430\u0434\u0438 \u0447\u0435\u0433\u043e \u0432\u0441\u0451 \u043d\u0430\u0447\u0438\u043d\u0430\u043b\u043e\u0441\u044c. \u0421\u0430\u043c\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b(<em>coroutine-core<\/em>) \u043d\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <code>MainCoroutineDispatcher<\/code>, \u0430 \u043b\u0438\u0448\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0435\u0433\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438. \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439 \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441 <code>MainDispatcherLoader<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>ServiceLoader<\/code> \u0438 <code>FastServiceLoader<\/code><em>(<\/em>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f <em>Android)<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043d\u043e \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c <code>kotlinx.coroutines.android.AndroidDispatcherFactory<\/code><em>. <\/em>\u0415\u0441\u043b\u0438 <code>MainDispatcherLoader<\/code><em> <\/em>\u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 <code>MainDispatcherFactory<\/code><em> <\/em>\u0438\u043b\u0438 <code>createDispatcher<\/code><em> <\/em>\u0432\u044b\u043a\u0438\u043d\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<em>, <\/em>\u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 <code>MissingMainCoroutineDispatcher<\/code><em>, <\/em>\u0432\u044b\u043a\u0438\u0434\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043d\u0430 \u0432\u0441\u0451 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f<em>. <\/em><\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432 <em>Android<\/em>:<\/p>\n<p>\u0412 <em>Android <\/em><code>MainCoroutineDispatcher<\/code><em> <\/em>\u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 <a href=\"https:\/\/github.com\/Kotlin\/kotlinx.coroutines\/blob\/master\/ui\/kotlinx-coroutines-android\/src\/HandlerDispatcher.kt#L114\" rel=\"noopener noreferrer nofollow\"><em>Handler<\/em><\/a><em>, <\/em>\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f <a href=\"https:\/\/github.com\/Kotlin\/kotlinx.coroutines\/blob\/master\/ui\/kotlinx-coroutines-android\/src\/HandlerDispatcher.kt#L114\" rel=\"noopener noreferrer nofollow\"><em>AndroidDispatcherFactory<\/em><\/a>:<\/p>\n<pre><code class=\"kotlin\">override fun createDispatcher(allFactories: List&lt;MainDispatcherFactory>): MainCoroutineDispatcher { val mainLooper = Looper.getMainLooper() ?: throw IllegalStateException(\"The main looper is not available\") return HandlerContext(mainLooper.asHandler(async = true)) }  @VisibleForTesting internal fun Looper.asHandler(async: Boolean): Handler { \/\/ Async support was added in API 16. if (!async || Build.VERSION.SDK_INT &lt; 16) { return Handler(this) } if (Build.VERSION.SDK_INT &amp;gt;= 28) {     \/\/ TODO compile against API 28 so this can be invoked without reflection.     val factoryMethod = Handler::class.java.getDeclaredMethod(\"createAsync\", Looper::class.java)     return factoryMethod.invoke(null, this) as Handler }  val constructor: Constructor&amp;lt;Handler&amp;gt; try {     constructor = Handler::class.java.getDeclaredConstructor(Looper::class.java,         Handler.Callback::class.java, Boolean::class.javaPrimitiveType) } catch (ignored: NoSuchMethodException) {     \/\/ Hidden constructor absent. Fall back to non-async constructor.     return Handler(this) } return constructor.newInstance(this, null, true) }<\/code><\/pre>\n<p>\u0421\u0430\u043c <code>HandlerContext<\/code> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 <code>MainCoroutineDispatcher<\/code><em> \u0441 <\/em><code>Delay<\/code><em> <\/em>\u0438 \u0432\u044b\u043d\u043e\u0441\u0438\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>Handler::post<\/code>:<\/p>\n<pre><code class=\"kotlin\">override fun dispatch(context: CoroutineContext, block: Runnable) { if (!handler.post(block)) { cancelOnRejection(context, block) } } <\/code><\/pre>\n<p><code>Delay<\/code><em> <\/em>\u0436\u0435 \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>delay()<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435, \u043d\u0430 <em>Android<\/em> \u0436\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/github.com\/Kotlin\/kotlinx.coroutines\/blob\/master\/ui\/kotlinx-coroutines-android\/src\/HandlerDispatcher.kt#L150\" rel=\"noopener noreferrer nofollow\"><em>handler.postDelayed<\/em><\/a>. \u0422\u0430\u043a \u0436\u0435 \u0442\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <a href=\"https:\/\/github.com\/Kotlin\/kotlinx.coroutines\/blob\/master\/ui\/kotlinx-coroutines-android\/src\/HandlerDispatcher.kt#L137\" rel=\"noopener noreferrer nofollow\"><em>isDispatchNeeded<\/em><\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043b\u044f <code>MainCoroutineDispatcher.immediate<\/code><em> <\/em>\u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c <code>dispatch<\/code><em> <\/em>\u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u0432\u044b \u0443\u0436\u0435 \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435.<\/p>\n<p><strong>\u0421\u0432\u043e\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f MainCoroutineDispatcher:<\/strong> \u041c\u043d\u0435 \u0441\u0442\u0430\u043b\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043a\u0430\u043a \u0436\u0435 \u0437\u0430\u0442\u0430\u0449\u0438\u0442\u044c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0432 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 Java, \u0441 \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c Event-Loop&#8217;\u043e\u043c. \u0411\u043b\u0430\u0433\u043e, \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 Java, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0441 Event-Loop \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u043c. \u041d\u0430\u0447\u0430\u0442\u044c \u0441\u0442\u043e\u0438\u0442 \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>MainCoroutineDispatcher<\/code>:<\/p>\n<pre><code class=\"kotlin\">internal class ServerDispatcher( private val invokeImmediately: Boolean ) : MainCoroutineDispatcher() { @Volatile private var _immediate = if (invokeImmediately) this else null  override val immediate = _immediate ?: ServerDispatcher(true).also { _immediate = it }  override fun isDispatchNeeded(context: CoroutineContext): Boolean =     !invokeImmediately || !Server.getInstance().isPrimaryThread  override fun dispatch(context: CoroutineContext, block: Runnable) {     Server.getInstance().scheduler.scheduleTask(block) }  override fun limitedParallelism(parallelism: Int): CoroutineDispatcher {     throw UnsupportedOperationException(\"limitedParallelism is not supported for ${this::class.qualifiedName}\") } }<\/code><\/pre>\n<p>\u0422\u0443\u0442 <code>isDispatchNeeded<\/code> \u043d\u0438\u0447\u0435\u043c \u043d\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0442\u0430\u043a\u043e\u0432\u043e\u0433\u043e \u0432 <em>Android, <\/em>\u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 \u0442\u0443\u0442 \u0432 <code>dispatch<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043b\u0430\u0434\u0435\u0442 <code>Runnable<\/code><em> <\/em>\u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0437\u0430\u0434\u0430\u0447, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u0446\u0438\u043a\u043b\u0435 \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435. \u0421\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:<\/p>\n<pre><code class=\"kotlin\">val scope = CoroutineScope(ServerDispatcher(invokeImmediately = false) + SupervisorJob()) scope.launch { logger.info(\"First message from coroutine!!\") delay(3000) logger.info(\"Message from coroutine after 3000ms delay on ${Thread.currentThread().name} thread!\") withContext(Dispatchers.IO) {     logger.info(\"Message from other context: ${Thread.currentThread().name}\") }  logger.info(\"You again on ${Thread.currentThread().name} thread!!!\") }  \/\/ \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: \/\/ 16:04:55 [INFO ] First message from coroutine!! \/\/ 16:04:58 [INFO ] Message from coroutine after 3000ms delay on main thread! \/\/ 16:04:58 [INFO ] Message from other context: DefaultDispatcher-worker-1 \/\/ 16:04:58 [INFO ] You again on main thread!!!<\/code><\/pre>\n<p> \u0423\u0431\u0435\u0434\u0438\u043b\u0438\u0441\u044c, \u0447\u0442\u043e \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0440\u0430 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0431\u0440\u0438\u043a\u0443:<\/p>\n<pre><code class=\"kotlin\">class ServerDispatcherFactory : MainDispatcherFactory { override val loadPriority: Int = Int.MAX_VALUE override fun createDispatcher(     allFactories: List&lt;MainDispatcherFactory>,   ): MainCoroutineDispatcher = ServerDispatcher(invokeImmediately = false) }<\/code><\/pre>\n<p>\u0418\u0434\u0451\u043c \u0432 \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0438 \u043a\u043b\u0430\u0434\u0435\u043c \u0444\u0430\u0439\u043b <code>kotlinx.coroutines.internal.MainDispatcherFactory<\/code> \u0432 <em>META-INF\/services<\/em> \u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c:<\/p>\n<pre><code class=\"kotlin\">dev.israpil.coroutines.mygameserver.ServerDispatcherFactory<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c:<\/p>\n<pre><code class=\"kotlin\">val scope = CoroutineScope(Dispatchers.Main.immediate + SupervisorJob()) scope.launch { logger.info(\"First message from coroutine!!\") delay(3000) logger.info(\"Message from coroutine after 3000ms delay on ${Thread.currentThread().name} thread!\") withContext(Dispatchers.IO) {     logger.info(\"Message from other context: ${Thread.currentThread().name}\") }  logger.info(\"You again on ${Thread.currentThread().name} thread!!!\") }  \/\/ \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: \/\/ 16:04:55 [INFO ] First message from coroutine!! \/\/ 16:04:58 [INFO ] Message from coroutine after 3000ms delay on main thread! \/\/ 16:04:58 [INFO ] Message from other context: DefaultDispatcher-worker-1 \/\/ 16:04:58 [INFO ] You again on main thread!!!<\/code><\/pre>\n<p>\u041d\u0430\u0441\u043b\u0430\u0436\u0434\u0430\u0435\u043c\u0441\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/680946\/\"> https:\/\/habr.com\/ru\/post\/680946\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u042f \u0434\u0443\u043c\u0430\u044e \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0435 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043b\u044e\u0434\u0435\u0439, \u043d\u0435\u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0445 \u0441 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438 \u0432 Kotlin. \u0412\u043e\u043b\u0448\u0435\u0431\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u044b? \u0415\u0449\u0451 \u0431\u043e\u043b\u0435\u0435 \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u044b\u043c \u0432 \u043d\u0438\u0445 \u044f \u043d\u0430\u0445\u043e\u0436\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0442\u043e\u043a:<\/p>\n<pre><code class=\"kotlin\">fun main() = runBlocking { println(\"Hello from ${Thread.currentThread().name}\")   withContext(Dispatchers.Default) {     println(\"Hello from ${Thread.currentThread().name}\") }  println(\"Welcome back to ${Thread.currentThread().name}\") }  \/\/ \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: \/\/ Hello from main \/\/ Hello from DefaultDispatcher-worker-2 \/\/ Welcome back to main <\/code><\/pre>\n<p>\u0412\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u0438 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442 \u0438\u0437 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430. \u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u044d\u0442\u043e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c? \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0434\u043e \u0431\u043e\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e, \u0435\u0441\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <code>CoroutineDispatcher<\/code>, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0442\u0430\u043c \u0434\u0432\u0430 \u0432\u0430\u0436\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<pre><code class=\"kotlin\">public open fun isDispatchNeeded(context: CoroutineContext): Boolean = true public abstract fun dispatch(context: CoroutineContext, block: Runnable)<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u0430 <code>dispatch<\/code>, \u0430 \u0432\u043e\u0442 \u0432\u0442\u043e\u0440\u043e\u0439 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435, \u043e\u043d \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0432 <code>block<\/code> <code>Runnable<\/code> \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435. \u0421\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e <code>dispatch<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 <code>block<\/code><em>, <\/em>\u0438\u043d\u0430\u0447\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u043b\u043e\u0432\u0438\u0442\u044c <em>deadlock<\/em> \u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 <strong>\u043d\u0438\u043a\u043e\u0433\u0434\u0430 <\/strong>\u043d\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u0442\u0430\u043a \u0436\u0435 \u043c\u0435\u0442\u043e\u0434 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d <strong>\u043d\u0435 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043e<\/strong> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c <code>block<\/code>, \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u043f\u043e\u0442\u043e\u043a\u0435 \u043b\u0443\u0447\u0448\u0435 \u0432\u0435\u0440\u043d\u0443\u0442\u044c <code>false<\/code><em> <\/em>\u0438\u0437 <code>isDispatchNeeded<\/code>.<\/p>\n<h3>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442?<\/h3>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c 4 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0434\u0438\u0441\u043f\u0430\u0442\u0435\u0440\u0430, \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Dispatchers<\/code>: Default, Unconfined, Main, IO. <\/p>\n<p><strong>Unconfined: <\/strong>\u0421\u0430\u043c\u044b\u043c \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0438\u0437 \u043d\u0438\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>Unconfined<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u0442\u043e\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438 \u043a\u043e\u0434 \u0438\u0437 \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0442\u0430\u0442\u044c\u0438 \u0443\u0436\u0435 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c:<\/p>\n<pre><code class=\"kotlin\">runBlocking(Dispatchers.Unconfined) { println(\"Hello from ${Thread.currentThread().name}\") withContext(Dispatchers.Default) {     println(\"Hello from ${Thread.currentThread().name}\") }  println(\"Welcome back to ${Thread.currentThread().name}\") }  \/\/ \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: \/\/ Hello from main \/\/ Hello from DefaultDispatcher-worker-2 \/\/ Welcome back to DefaultDispatcher-worker-2)<\/code><\/pre>\n<p>\u0414\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u0437\u0430 \u0441\u0447\u0435\u0442 <code>isDispatchNeeded<\/code><em> <\/em>\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0435\u0447\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>false<\/code><em> <\/em>\u0438 \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 <code>dispatch<\/code>(\u0421\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e\u0441\u0442\u0438 \u0440\u0430\u0434\u0438 \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e <code>dispatch<\/code><em> <\/em>\u0432\u0441\u0451 \u0442\u0430\u043a\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u043d \u0438\u0437 <code>yield(),<\/code> \u043d\u043e \u044d\u0442\u043e \u0443\u0436\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u0430\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f).<\/p>\n<p><strong>Default, IO: <\/strong>\u042d\u0442\u0438 \u0434\u0432\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 <code>ExecutorCoroutineDispatcher<\/code><em> <\/em>\u0441 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0432 \u0432\u0438\u0434\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0432\u043e\u0435\u0433\u043e <code>Executor'\u0430<\/code>, Default \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442 <code>SchedulerCoroutineDispatcher<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044f \u0438\u0445 \u0432 <code>CoroutineScheduler<\/code>, \u044d\u0442\u043e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 <code>Executor<\/code>, \u0441 \u043f\u0443\u043b\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0440\u0430\u0432\u043d\u043e\u043c\u0443 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430(\u043c\u0438\u043d\u0438\u043c\u0443\u043c 2) \u0434\u043b\u044f CPU-bound \u0437\u0430\u0434\u0430\u0447, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c\u0441\u044f \u0434\u043e <em>maxPoolSize<\/em>, \u0440\u0430\u0432\u043d\u044b\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u043c\u0443 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0443 <em>kotlinx.coroutines.scheduler.max.pool.size<\/em>, \u0438\u043b\u0438 <em>2097150 <\/em>\u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c, \u0434\u043b\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u0437\u0430\u0434\u0430\u0447(IO). IO Dispatcher \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0447\u0435\u0440\u0435\u0437 Default \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044f \u0441\u0435\u0431\u044f \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u0440\u0430\u0432\u043d\u044b\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u043c\u0443 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0443 <em>kotlinx.coroutines.io.parallelism <\/em>\u0438\u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430(\u043c\u0438\u043d\u0438\u043c\u0443\u043c 64)). <code>CoroutineScheduler<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0438\u043b\u0438 \u043d\u0435\u0442 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>dispatchWithContext<\/code><em> <\/em>\u0443 <code>SchedulerCoroutineDispatcher<\/code><em>, <\/em>\u0433\u0434\u0435 \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0438\u043f \u0437\u0430\u0434\u0430\u0447\u0438: <code>BlockingContext<\/code><em> <\/em>\u0438\u0437 <em>IO<\/em> \u0438 <em>NonBlocking <\/em>\u0434\u043b\u044f \u043b\u044e\u0431\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0438\u0437 <code>Default<\/code><em>.<\/em><\/p>\n<p><strong>Main<\/strong>: \u0422\u043e, \u0440\u0430\u0434\u0438 \u0447\u0435\u0433\u043e \u0432\u0441\u0451 \u043d\u0430\u0447\u0438\u043d\u0430\u043b\u043e\u0441\u044c. \u0421\u0430\u043c\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b(<em>coroutine-core<\/em>) \u043d\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <code>MainCoroutineDispatcher<\/code>, \u0430 \u043b\u0438\u0448\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0435\u0433\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438. \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439 \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441 <code>MainDispatcherLoader<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>ServiceLoader<\/code> \u0438 <code>FastServiceLoader<\/code><em>(<\/em>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f <em>Android)<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043d\u043e \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c <code>kotlinx.coroutines.android.AndroidDispatcherFactory<\/code><em>. <\/em>\u0415\u0441\u043b\u0438 <code>MainDispatcherLoader<\/code><em> <\/em>\u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 <code>MainDispatcherFactory<\/code><em> <\/em>\u0438\u043b\u0438 <code>createDispatcher<\/code><em> <\/em>\u0432\u044b\u043a\u0438\u043d\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<em>, <\/em>\u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 <code>MissingMainCoroutineDispatcher<\/code><em>, <\/em>\u0432\u044b\u043a\u0438\u0434\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043d\u0430 \u0432\u0441\u0451 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f<em>. <\/em><\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432 <em>Android<\/em>:<\/p>\n<p>\u0412 <em>Android <\/em><code>MainCoroutineDispatcher<\/code><em> <\/em>\u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 <a href=\"https:\/\/github.com\/Kotlin\/kotlinx.coroutines\/blob\/master\/ui\/kotlinx-coroutines-android\/src\/HandlerDispatcher.kt#L114\" rel=\"noopener noreferrer nofollow\"><em>Handler<\/em><\/a><em>, <\/em>\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f <a href=\"https:\/\/github.com\/Kotlin\/kotlinx.coroutines\/blob\/master\/ui\/kotlinx-coroutines-android\/src\/HandlerDispatcher.kt#L114\" rel=\"noopener noreferrer nofollow\"><em>AndroidDispatcherFactory<\/em><\/a>:<\/p>\n<pre><code class=\"kotlin\">override fun createDispatcher(allFactories: List&lt;MainDispatcherFactory>): MainCoroutineDispatcher { val mainLooper = Looper.getMainLooper() ?: throw IllegalStateException(\"The main looper is not available\") return HandlerContext(mainLooper.asHandler(async = true)) }  @VisibleForTesting internal fun Looper.asHandler(async: Boolean): Handler { \/\/ Async support was added in API 16. if (!async || Build.VERSION.SDK_INT &lt; 16) { return Handler(this) } if (Build.VERSION.SDK_INT &amp;gt;= 28) {     \/\/ TODO compile against API 28 so this can be invoked without reflection.     val factoryMethod = Handler::class.java.getDeclaredMethod(\"createAsync\", Looper::class.java)     return factoryMethod.invoke(null, this) as Handler }  val constructor: Constructor&amp;lt;Handler&amp;gt; try {     constructor = Handler::class.java.getDeclaredConstructor(Looper::class.java,         Handler.Callback::class.java, Boolean::class.javaPrimitiveType) } catch (ignored: NoSuchMethodException) {     \/\/ Hidden constructor absent. Fall back to non-async constructor.     return Handler(this) } return constructor.newInstance(this, null, true) }<\/code><\/pre>\n<p>\u0421\u0430\u043c <code>HandlerContext<\/code> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 <code>MainCoroutineDispatcher<\/code><em> \u0441 <\/em><code>Delay<\/code><em> <\/em>\u0438 \u0432\u044b\u043d\u043e\u0441\u0438\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>Handler::post<\/code>:<\/p>\n<pre><code class=\"kotlin\">override fun dispatch(context: CoroutineContext, block: Runnable) { if (!handler.post(block)) { cancelOnRejection(context, block) } } <\/code><\/pre>\n<p><code>Delay<\/code><em> <\/em>\u0436\u0435 \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>delay()<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435, \u043d\u0430 <em>Android<\/em> \u0436\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/github.com\/Kotlin\/kotlinx.coroutines\/blob\/master\/ui\/kotlinx-coroutines-android\/src\/HandlerDispatcher.kt#L150\" rel=\"noopener noreferrer nofollow\"><em>handler.postDelayed<\/em><\/a>. \u0422\u0430\u043a \u0436\u0435 \u0442\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <a href=\"https:\/\/github.com\/Kotlin\/kotlinx.coroutines\/blob\/master\/ui\/kotlinx-coroutines-android\/src\/HandlerDispatcher.kt#L137\" rel=\"noopener noreferrer nofollow\"><em>isDispatchNeeded<\/em><\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043b\u044f <code>MainCoroutineDispatcher.immediate<\/code><em> <\/em>\u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c <code>dispatch<\/code><em> <\/em>\u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u0432\u044b \u0443\u0436\u0435 \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435.<\/p>\n<p><strong>\u0421\u0432\u043e\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f MainCoroutineDispatcher:<\/strong> \u041c\u043d\u0435 \u0441\u0442\u0430\u043b\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043a\u0430\u043a \u0436\u0435 \u0437\u0430\u0442\u0430\u0449\u0438\u0442\u044c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0432 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 Java, \u0441 \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c Event-Loop&#8217;\u043e\u043c. \u0411\u043b\u0430\u0433\u043e, \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 Java, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0441 Event-Loop \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u043c. \u041d\u0430\u0447\u0430\u0442\u044c \u0441\u0442\u043e\u0438\u0442 \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>MainCoroutineDispatcher<\/code>:<\/p>\n<pre><code class=\"kotlin\">internal class ServerDispatcher( private val invokeImmediately: Boolean ) : MainCoroutineDispatcher() { @Volatile private var _immediate = if (invokeImmediately) this else null  override val immediate = _immediate ?: ServerDispatcher(true).also { _immediate = it }  override fun isDispatchNeeded(context: CoroutineContext): Boolean =     !invokeImmediately || !Server.getInstance().isPrimaryThread  override fun dispatch(context: CoroutineContext, block: Runnable) {     Server.getInstance().scheduler.scheduleTask(block) }  override fun limitedParallelism(parallelism: Int): CoroutineDispatcher {     throw UnsupportedOperationException(\"limitedParallelism is not supported for ${this::class.qualifiedName}\") } }<\/code><\/pre>\n<p>\u0422\u0443\u0442 <code>isDispatchNeeded<\/code> \u043d\u0438\u0447\u0435\u043c \u043d\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0442\u0430\u043a\u043e\u0432\u043e\u0433\u043e \u0432 <em>Android, <\/em>\u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 \u0442\u0443\u0442 \u0432 <code>dispatch<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043b\u0430\u0434\u0435\u0442 <code>Runnable<\/code><em> <\/em>\u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0437\u0430\u0434\u0430\u0447, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u0446\u0438\u043a\u043b\u0435 \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435. \u0421\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:<\/p>\n<pre><code class=\"kotlin\">val scope = CoroutineScope(ServerDispatcher(invokeImmediately = false) + SupervisorJob()) scope.launch { logger.info(\"First message from coroutine!!\") delay(3000) logger.info(\"Message from coroutine after 3000ms delay on ${Thread.currentThread().name} thread!\") withContext(Dispatchers.IO) {     logger.info(\"Message from other context: ${Thread.currentThread().name}\") }  logger.info(\"You again on ${Thread.currentThread().name} thread!!!\") }  \/\/ \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: \/\/ 16:04:55 [INFO ] First message from coroutine!! \/\/ 16:04:58 [INFO ] Message from coroutine after 3000ms delay on main thread! \/\/ 16:04:58 [INFO ] Message from other context: DefaultDispatcher-worker-1 \/\/ 16:04:58 [INFO ] You again on main thread!!!<\/code><\/pre>\n<p> \u0423\u0431\u0435\u0434\u0438\u043b\u0438\u0441\u044c, \u0447\u0442\u043e \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0440\u0430 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0431\u0440\u0438\u043a\u0443:<\/p>\n<pre><code class=\"kotlin\">class ServerDispatcherFactory : MainDispatcherFactory { override val loadPriority: Int = Int.MAX_VALUE override fun createDispatcher(     allFactories: List&lt;MainDispatcherFactory>,   ): MainCoroutineDispatcher = ServerDispatcher(invokeImmediately = false) }<\/code><\/pre>\n<p>\u0418\u0434\u0451\u043c \u0432 \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0438 \u043a\u043b\u0430\u0434\u0435\u043c \u0444\u0430\u0439\u043b <code>kotlinx.coroutines.internal.MainDispatcherFactory<\/code> \u0432 <em>META-INF\/services<\/em> \u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c:<\/p>\n<pre><code class=\"kotlin\">dev.israpil.coroutines.mygameserver.ServerDispatcherFactory<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c:<\/p>\n<pre><code class=\"kotlin\">val scope = CoroutineScope(Dispatchers.Main.immediate + SupervisorJob()) scope.launch { logger.info(\"First message from coroutine!!\") delay(3000) logger.info(\"Message from coroutine after 3000ms delay on ${Thread.currentThread().name} thread!\") withContext(Dispatchers.IO) {     logger.info(\"Message from other context: ${Thread.currentThread().name}\") }  logger.info(\"You again on ${Thread.currentThread().name} thread!!!\") }  \/\/ \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: \/\/ 16:04:55 [INFO ] First message from coroutine!! \/\/ 16:04:58 [INFO ] Message from coroutine after 3000ms delay on main thread! \/\/ 16:04:58 [INFO ] Message from other context: DefaultDispatcher-worker-1 \/\/ 16:04:58 [INFO ] You again on main thread!!!<\/code><\/pre>\n<p>\u041d\u0430\u0441\u043b\u0430\u0436\u0434\u0430\u0435\u043c\u0441\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/680946\/\"> https:\/\/habr.com\/ru\/post\/680946\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-336589","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336589","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=336589"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336589\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=336589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=336589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=336589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}