Example usage for android.os Process THREAD_PRIORITY_DISPLAY

List of usage examples for android.os Process THREAD_PRIORITY_DISPLAY

Introduction

In this page you can find the example usage for android.os Process THREAD_PRIORITY_DISPLAY.

Prototype

int THREAD_PRIORITY_DISPLAY

To view the source code for android.os Process THREAD_PRIORITY_DISPLAY.

Click Source Link

Document

Standard priority of system display threads, involved in updating the user interface.

Usage

From source file:com.facebook.react.ReactInstanceManager.java

@ThreadConfined(UI)
private void runCreateReactContextOnNewThread(final ReactContextInitParams initParams) {
    Log.d(ReactConstants.TAG, "ReactInstanceManager.runCreateReactContextOnNewThread()");
    UiThreadUtil.assertOnUiThread();//  w ww . j  a  v  a2s  .  c o  m
    synchronized (mReactContextLock) {
        if (mCurrentReactContext != null) {
            tearDownReactContext(mCurrentReactContext);
            mCurrentReactContext = null;
        }
    }

    mCreateReactContextThread = new Thread(null, new Runnable() {
        @Override
        public void run() {
            ReactMarker.logMarker(REACT_CONTEXT_THREAD_END);
            synchronized (ReactInstanceManager.this.mHasStartedDestroying) {
                while (ReactInstanceManager.this.mHasStartedDestroying) {
                    try {
                        ReactInstanceManager.this.mHasStartedDestroying.wait();
                    } catch (InterruptedException e) {
                        continue;
                    }
                }
            }
            // As destroy() may have run and set this to false, ensure that it is true before we create
            mHasStartedCreatingInitialContext = true;

            try {
                Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY);
                ReactMarker.logMarker(VM_INIT);
                final ReactApplicationContext reactApplicationContext = createReactContext(
                        initParams.getJsExecutorFactory().create(), initParams.getJsBundleLoader());

                mCreateReactContextThread = null;
                ReactMarker.logMarker(PRE_SETUP_REACT_CONTEXT_START);
                final Runnable maybeRecreateReactContextRunnable = new Runnable() {
                    @Override
                    public void run() {
                        if (mPendingReactContextInitParams != null) {
                            runCreateReactContextOnNewThread(mPendingReactContextInitParams);
                            mPendingReactContextInitParams = null;
                        }
                    }
                };
                Runnable setupReactContextRunnable = new Runnable() {
                    @Override
                    public void run() {
                        try {
                            setupReactContext(reactApplicationContext);
                        } catch (Exception e) {
                            mDevSupportManager.handleException(e);
                        }
                    }
                };

                reactApplicationContext.runOnNativeModulesQueueThread(setupReactContextRunnable);
                UiThreadUtil.runOnUiThread(maybeRecreateReactContextRunnable);
            } catch (Exception e) {
                mDevSupportManager.handleException(e);
            }
        }
    }, "create_react_context");
    ReactMarker.logMarker(REACT_CONTEXT_THREAD_START);
    mCreateReactContextThread.start();
}