Advertisement
rahat14

excutor class ()sakib vai !!!

Dec 2nd, 2020
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. // init on a clas
  2.     private static volatile CartDatabase INSTANCE;
  3.     private static final int NUMBER_OF_THREADS = 2;
  4.     public static final ExecutorService databaseWriteExecutor =
  5.             Executors.newFixedThreadPool(NUMBER_OF_THREADS);
  6.  
  7.     public static CartDatabase getDatabase(final Context context) {
  8.         if (INSTANCE == null) {
  9.             synchronized (CartDatabase.class) {
  10.                 if (INSTANCE == null) {
  11.                     INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
  12.                             CartDatabase.class, DB_NAME)
  13.                             .fallbackToDestructiveMigration()
  14.                             .allowMainThreadQueries()
  15.                             .build();
  16.                 }
  17.             }
  18.         }
  19.         return INSTANCE;
  20.     }
  21.  
  22. }
  23.  
  24.  
  25. //calling
  26. CartDatabase.databaseWriteExecutor.execute(new Runnable() {
  27.                         @Override
  28.                         public void run() {
  29.                             CartDatabase.getDatabase(getApplicationContext()).dao().nukeCartTable();
  30.                             runOnUiThread(new Runnable() {
  31.                                 @Override
  32.                                 public void run() {
  33.                                     dialog.dismiss();
  34.                                     Intent p = new Intent(getApplicationContext(), OrderDone.class);
  35.                                     startActivity(p);
  36.                                     finish();
  37.                                 }
  38.                             });
  39.                         }
  40.  
  41.                     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement