-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Pull Request resolved: #45702 # Changelog: [Internal] - As in the title. Reviewed By: tdn120 Differential Revision: D60282843 fbshipit-source-id: b43262d62d35d9cf172b90ab0c95d100dea43e26
- Loading branch information
Showing
2 changed files
with
44 additions
and
53 deletions.
There are no files selected for viewing
53 changes: 0 additions & 53 deletions
53
...ative/ReactAndroid/src/main/java/com/facebook/react/runtime/internal/bolts/Executors.java
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
...-native/ReactAndroid/src/main/java/com/facebook/react/runtime/internal/bolts/Executors.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.runtime.internal.bolts | ||
|
||
import com.facebook.react.bridge.UiThreadUtil | ||
import java.util.concurrent.Executor | ||
|
||
/** | ||
* This was created because the helper methods in [java.util.concurrent.Executors] do not work as | ||
* people would normally expect. | ||
* | ||
* Normally, you would think that a cached thread pool would create new threads when necessary, | ||
* queue them when the pool is full, and kill threads when they've been inactive for a certain | ||
* period of time. This is not how [java.util.concurrent.Executors.newCachedThreadPool] works. | ||
* | ||
* Instead, [java.util.concurrent.Executors.newCachedThreadPool] executes all tasks on a new or | ||
* cached thread immediately because corePoolSize is 0, SynchronousQueue is a queue with size 0 and | ||
* maxPoolSize is Integer.MAX_VALUE. This is dangerous because it can create an unchecked amount of | ||
* threads. | ||
*/ | ||
internal object Executors { | ||
@JvmField public val UI_THREAD: Executor = UIThreadExecutor() | ||
@JvmField public val IMMEDIATE: Executor = ImmediateExecutor() | ||
|
||
private class UIThreadExecutor : Executor { | ||
override fun execute(command: Runnable) { | ||
UiThreadUtil.runOnUiThread(command) | ||
} | ||
} | ||
|
||
/** | ||
* An [java.util.concurrent.Executor] that schedules tasks to run asynchronously on the UI thread. | ||
*/ | ||
private class ImmediateExecutor : Executor { | ||
override fun execute(command: Runnable) { | ||
command.run() | ||
} | ||
} | ||
} |