davidfoerster/KaleidOK-examples

Thread for every image result

Closed this issue · 3 comments

From @Disastergirl on May 26, 2015 11:37

Threading is needed to continue the animation while the requests for data continue to run.
Create a bunch of "worker threads" and have those worker threads go through a common job queue.

  • be aware of array lengths
  • bring in additional variables
  • set a new boolean to avoid errors

Copied from original issue: Disastergirl/Kaleidoscope#5

I agree, that some tasks should be loaded off to worker threads, in particular long input/output operations like network requests (e. g. search requests and resource/image downloads) and later some computational tasks (e. g. speech transcription or other complex audio analyses). An alternative for I/O would be an event handler loop waiting for termination of those operations and dispatching their results (reactor pattern).

The current event handling is a sham, because long, blocking (network) operations run synchronously in the event dispatcher thread of the user interface, stalling/freezing it in the mean time.

This requires some sort of synchronisation between concurrent threads, of course, and your recommendations go into the right direction, but you seem to be unaware, that Java provides

  1. the synchronize keyword to denote critical sections handled and enforced by the runtime environment and
  2. container classes, that pretty much synchronise themselves based on the above critical sections and that should be used instead of arrays for concurrent access.

I am unaware of what Java provides. But I emphasise that working on this is vital for user experience.

Implemented as of 6212ddb.