EventBus icon indicating copy to clipboard operation
EventBus copied to clipboard

why backgroundposter's run methond use loop

Open topone37 opened this issue 7 years ago • 2 comments

topone37 avatar Jan 25 '19 05:01 topone37

    public void run() {
        try {
            try {
                while (true) {
                    PendingPost pendingPost = queue.poll(1000);
                    if (pendingPost == null) {
                        synchronized (this) {
                            // Check again, this time in synchronized
                            pendingPost = queue.poll();
                            if (pendingPost == null) {
                                executorRunning = false;
                                return;
                            }
                        }
                    }
                    eventBus.invokeSubscriber(pendingPost);
                }
            } catch (InterruptedException e) {
                eventBus.getLogger().log(Level.WARNING, Thread.currentThread().getName() + " was interruppted", e);
            }
        } finally {
            executorRunning = false;
        }
    }

topone37 avatar Jan 25 '19 05:01 topone37

A new event might have come in. This is to reduce the number of times the background poster thread is stopped and restarted (which is expensive). -ut

greenrobot-team avatar Mar 05 '19 06:03 greenrobot-team