Note that there are some explanatory texts on larger screens.

plurals
  1. POExecutor wait for ever in a singleton class
    primarykey
    data
    text
    <p>I have implemented a singleton (manager) to manage some related tasks, inside this manager I am using an executor to handle 10 task at the same time, I was using linkedBlockingQueue with no limit, and that's working good so far, but now I need to set a limitation to my executor queue because I have a lot of tasks (hundreds of thousands tasks), and I don’t want to put them all in my queue that causing me a performance issues, so what I have done:</p> <p>here is my Executor :</p> <pre><code>public class MyThreadPoolExecutor extends ThreadPoolExecutor { public MyThreadPoolExecutor(int corePoolSize, BlockingQueue&lt;Runnable&gt; workQueue) { super(corePoolSize, corePoolSize + 5, 500, TimeUnit.MILLISECONDS, workQueue); } @Override protected void beforeExecute(Thread t, Runnable r) { super.beforeExecute(t, r); //Do something to my task } @Override protected void afterExecute(Runnable r, Throwable t) { super.afterExecute(r, t); if(t != null) { // } else { //Do something to my task } } } </code></pre> <p>and here is my manager :</p> <pre><code>public final class MyManager { private static MyManager manager = new MyManager(); public static final int queueMaxSize = 100; private BlockingQueue&lt;Runnable&gt; workQueue = new ArrayBlockingQueue&lt;Runnable&gt;(queueMaxSize); private ExecutorService executor = new MyThreadPoolExecutor(10, workQueue); /** * constructor */ private MyManager() {} public static MyManager getInstance(){ if (manager == null){ synchronized(MyManager.class){ if (manager == null){ manager = new MyManager(); } } } return manager; } /** */ public void executeTask(Integer key){ executeTask(key, Locale.getDefault()); } /** */ public void executeTask(Integer key, Locale locale) { Tasker task = new Tasker(key, locale); executor.execute(task); } } </code></pre> <p>and here the class that asking to do the tasks :</p> <pre><code>public class MyClass { public void doTasks() { //geting my tasks in array of list, its holding more than 900 000 tasks, //sometimes its holding up to 10 million task like : MyManager.getInstance().isFull() {\\wait, then ask again} ArrayList&lt;Integer&gt; myTasks = getAllTasksIds(); for(Integer id : myTasks) { //if i perform a waiting here it will be waiting for ever. MyManaget.getInstance().executeTask(id); } } } </code></pre> <p>What I want exactly to wait the executor until finish his queue tasks, then re-full it again.</p> <p>But the problem is when I try to wait based on queue size, the executor won’t work, and its wait forever because the queue still full.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload