Schedule CatalystInstanceImpl destruction using new thread (#41720)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41720 We currently go via the UI thread, so we can use AsyncTask to schedule the final bit of async ReactContext destruction. This is a requirement for the AsyncTask API, which is also deprecated. We should figure out a better way to schedule and re-use threads across React Native Android, but until then, we can just create a new Thread here, which is also what we do for instance creation. Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D51706689 fbshipit-source-id: cf17e20e91b195b956b1701e6d91d563fdba4d15
This commit is contained in:
Родитель
847f5dedcc
Коммит
dbf0984682
|
@ -11,7 +11,6 @@ import static com.facebook.infer.annotation.ThreadConfined.UI;
|
||||||
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||||
|
|
||||||
import android.content.res.AssetManager;
|
import android.content.res.AssetManager;
|
||||||
import android.os.AsyncTask;
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.facebook.common.logging.FLog;
|
import com.facebook.common.logging.FLog;
|
||||||
import com.facebook.infer.annotation.Assertions;
|
import com.facebook.infer.annotation.Assertions;
|
||||||
|
@ -374,30 +373,24 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||||
mTurboModuleRegistry.invalidate();
|
mTurboModuleRegistry.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
getReactQueueConfiguration()
|
// Kill non-UI threads from neutral third party
|
||||||
.getUIQueueThread()
|
// potentially expensive, so don't run on UI thread
|
||||||
.runOnQueue(
|
new Thread(
|
||||||
() -> {
|
() -> {
|
||||||
// AsyncTask.execute must be executed from the UI Thread
|
// contextHolder is used as a lock to guard against
|
||||||
AsyncTask.execute(
|
// other users of the JS VM having the VM destroyed
|
||||||
() -> {
|
// underneath them, so notify them before we reset
|
||||||
// Kill non-UI threads from neutral third party
|
// Native
|
||||||
// potentially expensive, so don't run on UI thread
|
mJavaScriptContextHolder.clear();
|
||||||
|
|
||||||
// contextHolder is used as a lock to guard against
|
mHybridData.resetNative();
|
||||||
// other users of the JS VM having the VM destroyed
|
getReactQueueConfiguration().destroy();
|
||||||
// underneath them, so notify them before we reset
|
FLog.w(ReactConstants.TAG, "CatalystInstanceImpl.destroy() end");
|
||||||
// Native
|
ReactMarker.logMarker(
|
||||||
mJavaScriptContextHolder.clear();
|
ReactMarkerConstants.DESTROY_CATALYST_INSTANCE_END);
|
||||||
|
},
|
||||||
mHybridData.resetNative();
|
"destroy_react_context")
|
||||||
getReactQueueConfiguration().destroy();
|
.start();
|
||||||
FLog.d(
|
|
||||||
ReactConstants.TAG, "CatalystInstanceImpl.destroy() end");
|
|
||||||
ReactMarker.logMarker(
|
|
||||||
ReactMarkerConstants.DESTROY_CATALYST_INSTANCE_END);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче