/** * Display messages until none are left to display. Then reset the * registered thread name and die. */ @Override public void run() { while (!eventBuffer.isEmpty()) { showMessage(eventBuffer.poll()); } messengerThreadName.set(""); // If another thread has added new events just before the // messengerThreadName was reset here, then it could happen that the // messenger dies while there is still work to do. To avoid this, we // check again one last time, and create a new messenger if needed: if (!eventBuffer.isEmpty()) { ensureMessengerRuns(); } }