Using executor on android

0

I'm trying to use an executor to write data to the bank using threads. When instantiating an Executor Service class object and retrieving an instance of Executors.newSingleThreadExecutor (); it returns the error that is not finding the instance / declaration of newSingleThreadExecutor.

   ExecutorService exec = new Executors.newSingleThreadExecutor();

                       exec.execute(new Runnable() {
                            @Override
                            public void run() {

                                //Adicionando tarefa
                                addTask(itemList);

                            }
                        });
    
asked by anonymous 24.02.2018 / 18:33

1 answer

1

Do not use new .

Executors.newSingleThreadExecutor() is a method, not a class.

ExecutorService exec = Executors.newSingleThreadExecutor();

Its function is to create an instance of ExecutorService which in this case uses a single worker thread .

    
24.02.2018 / 18:49