Which are the recomended arguments to use when del

2019-08-20 07:00发布

I'm using the following method to delete a Cloud Firestore collection as explained here.

deleteCollection(
    final CollectionReference collection,
    final int batchSize,
    Executor executor)

I have tried to use each one of the following three Executors and it works fine with which one of them.

ExecutorService executorService = Executors.newFixedThreadPool(5);
ExecutorService executorService = Executors.newCachedThreadPool();
ExecutorService executorService = Executors.newSingleThreadExecutor();

Which one is recomended to be more efficient and used when calling deleteCollection() method? Or is there a better one? What is the recommended batchSize we need to use to avoid out-of-memory errors?

Thnak you in advance!

1条回答
Juvenile、少年°
2楼-- · 2019-08-20 07:14

The sample code you see there for Android comes directly from this code in GitHub. Digging around in there, you can see that the sample coded uses the following Executor:

private static final ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(2, 4,
    60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());

Whether or not that's the best possible case for your particular situation, that's not really possible to say.

Regarding the batch size, the documentation also suggests that you need to make a judgement call:

If you have larger collections, you may want to delete the documents in smaller batches to avoid out-of-memory errors.

Given that we don't really know your specific situation, it's not really possible to give an answer that definitively gives you a best-possible solution.

查看更多
登录 后发表回答