/*
 * Copyright 2014-present Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.facebook.litho;

import com.facebook.litho.config.LayoutThreadPoolConfiguration;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadPoolExecutor;

/** LayoutHandler implementation that uses a thread pool to calculate the layout. */
public class ThreadPoolLayoutHandler implements LayoutHandler {

  private final ThreadPoolExecutor mLayoutThreadPoolExecutor;

  public ThreadPoolLayoutHandler(LayoutThreadPoolConfiguration configuration) {
    mLayoutThreadPoolExecutor =
        new LayoutThreadPoolExecutor(
            configuration.getCorePoolSize(),
            configuration.getMaxPoolSize(),
            configuration.getThreadPriority());
  }

  @Override
  public boolean post(Runnable runnable) {
    try {
      mLayoutThreadPoolExecutor.execute(runnable);
      return true;
    } catch (RejectedExecutionException e) {
      throw new RuntimeException("Cannot execute layout calculation task; " + e);
    }
  }

  @Override
  public void removeCallbacks(Runnable runnable) {
    mLayoutThreadPoolExecutor.remove(runnable);
  }

  @Override
  public void removeCallbacksAndMessages(Object token) {
    throw new RuntimeException("Operation not supported");
  }
}

@@ -959,13 +959,14 @@
 ate 
-final
+static
  Thr
@@ -981,17 +981,17 @@
 xecutor 
-m
+s
 LayoutTh
@@ -1085,33 +1085,80 @@
 guration) %7B%0A    
-m
+if (sLayoutThreadPoolExecutor == null) %7B%0A      s
 LayoutThreadPool
@@ -1168,16 +1168,18 @@
 cutor =%0A
+  
         
@@ -1212,32 +1212,34 @@
 or(%0A            
+ 
+ 
 configuration.ge
@@ -1259,32 +1259,34 @@
 (),%0A            
+  
 configuration.ge
@@ -1305,32 +1305,34 @@
 (),%0A            
+ 
+ 
 configuration.ge
@@ -1351,16 +1351,22 @@
 ity());%0A
+    %7D%0A
   %7D%0A%0A  @
@@ -1429,25 +1429,25 @@
 try %7B%0A      
-m
+s
 LayoutThread
@@ -1702,17 +1702,17 @@
 ) %7B%0A    
-m
+s
 LayoutTh

Create a single thread pool per app