title: Task rejected from java.util.concurrent.ThreadPoolExecutor
body: <p>My database:</p>
  <pre><code>@Database(entities = {Sensor.class}, version = 1, exportSchema = false)
  public abstract class LocalDatabase extends RoomDatabase {
      public abstract SensorDao sensorDao();
  
      private static volatile LocalDatabase INSTANCE;
      private static final int NUMBER_OF_THREADS = 4;
      static final ExecutorService databaseWriteExecutor =
              Executors.newFixedThreadPool(NUMBER_OF_THREADS);
  
      static LocalDatabase getDatabase(final Context context) {
          if (INSTANCE == null) {
              synchronized (LocalDatabase.class) {
                  if (INSTANCE == null) {
                      INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                              LocalDatabase.class, &quot;efento-database&quot;)
                              .build();
                  }
              }
          }
          return INSTANCE;
      }
  
  }
  </code></pre>
  <p>RecyclerView Adapter (gives error):</p>
  <pre><code>registerBtn.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      String mac = devices.get(getLayoutPosition()).getAddress();
                      if(!regSensors.contains(mac)) {
                          LocalDatabase.databaseWriteExecutor.execute(() -&gt; {
                              LocalDatabase.getDatabase(context).sensorDao().insertSensor(new Sensor(mac));
                          });
                          registerBtn.setText(&quot;Unregister&quot;);
                      }
                  }
              });
  </code></pre>
  <p>Main Activty (this runs fine):</p>
  <pre><code>LocalDatabase.databaseWriteExecutor.execute(() -&gt; {
              db = LocalDatabase.getDatabase(this);
              sensorDao = db.sensorDao();
              regSensors = (ArrayList&lt;String&gt;) sensorDao.getAllAddress();
          });
          LocalDatabase.databaseWriteExecutor.shutdown();
          try {
              LocalDatabase.databaseWriteExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
          } catch (InterruptedException e) {  }
  </code></pre>
  <p>Error:</p>
  <pre><code>java.util.concurrent.RejectedExecutionException: Task com.hamza.enfentodb.bleListAdapter$ViewHolder$1$$ExternalSyntheticLambda0@4ed5679 rejected from java.util.concurrent.ThreadPoolExecutor@3fcdfbe[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 1]
          at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2085)
          at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:848)
          at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1394)
          at com.hamza.enfentodb.bleListAdapter$ViewHolder$1.onClick(bleListAdapter.java:42)
  </code></pre>
  <p>I am not sure why I am getting this error. I doubt its due to the executorService.shutdown(). I need to use that in MainActivity to make sure I get the regSensor List before continuing.</p>