How to get the number of tasks in a queue in executor service?

361
September 03, 2017, at 12:17 PM

So I am using executorservice to create a threadpool.

ExecutorService executor = Executors.newSingleThreadExecutor();

I am trying to access the number of tasks in the queue of the threadpool. I see that there are no methods to get that. I know there are methods to get the queue size in threadpoolexecutor but how can I do that with executorservice object.

Like I said I can get the queue information if I have created a ThreadpoolExecutor like this

ThreadPoolExecutor tpExecutor =  new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>());

I know I can use the tpExecutor.queue.size() to get the number of tasks in queue of threadpool. But currently I have declared my threadpool using Executor Service. How can I do that? It would be appreciable if people can write code and demonstrate.

Rent Charter Buses Company
READ ALSO
Java BufferedImage loading not working | problems with the path

Java BufferedImage loading not working | problems with the path

I have a method that converts a image to buffered image

517
spring security with angularJS web app and android app

spring security with angularJS web app and android app

I have been working on a medical emergency project, which involves the use of android app to send alerts and a web app (AngularJS) as a control centre that can see alerts, location of request and keeps tracking the location, BackEnd is java maven

373
JavaFx pane in pane resizing

JavaFx pane in pane resizing

How I can resize Pane in GridPane? I'm creating a GUI which is GridPane and a map in itAnd when gui change it's size I want to map which is in another Pane to resize

711
Is my program right? Java

Is my program right? Java

So what my program is supposed to do is read user input and print out all the prime numbers leading up to itSo for example, if I input 20 it should print out 2, 3, 5, 7,

333