Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


What concurrency mechanism is used in the SWT version of ColorBoxes to handle 'stars' color change?

  1. synchronized blocks

  2. java.util.Timer

  3. getDisplay().asyncExec(new Runnable())

  4. java.util.concurrent.ExecutorService

The correct answer is: getDisplay().asyncExec(new Runnable())

The SWT version of ColorBoxes uses the getDisplay().asyncExec(new Runnable()) concurrency mechanism for handling the color change of 'stars'. This is because SWT is based on the Event Dispatch Thread (EDT) model, where all UI updates must be performed on the main thread. This allows the color changes to be synchronized with the UI updates, ensuring that they happen at the correct time. Options A, B, and D are all incorrect as they are not specific to the SWT version of ColorBoxes and may not guarantee that the color changes are synchronized with the UI updates.