Skip to content

A method of maintaining FIFO order for related events while using a shared ExecutorService processor

License

Notifications You must be signed in to change notification settings

griffinjm/FifoThreadMuxer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FifoThreadMuxer

The FifoThreadMuxer provides a method of maintaining FIFO order for related tasks while using a shared ExecutorService processor. Using an approach similar to the standard Java HashMap Collection, it uses a bucketing approach to queue related tasks. This typically has applications in event driven systems where the order of related tasks needs to be maintained.

Methodology visualisation

Methodology

  1. Hashes the provided fifoValue String
  2. "Smears" that first hash with a function provided by the JCP JSR-166 Expert Group (to protect against poor hashes)
  3. Bitwise ANDs the returned int with the number of available threads
  4. The remainder is then used to determine which thread the submitted task will be executed on
  5. Each thread in the ExecutorService is running a MuxerWorker task which continuously performs a blocking take on a single LinkedBlockingQueue of Runnables which ensures that thread will only execute tasks submitted to that queue.

This ensures that tasks submitted with the same fifoValue will be processed in the order that they were submitted while also allowing for 'muxing' of other unrelated events on the same thread.

FIFO

FIFO is an acronym for first in, first out, a method for organizing and manipulating a data buffer, where the oldest (first) entry, or 'head' of the queue, is processed first. It is analogous to processing a queue with first-come, first-served (FCFS) behaviour: where the people leave the queue in the order in which they arrive. Wikipedia

Thread

A thread of execution is the smallest sequence of programmed instructions that can be managed independently by a scheduler, which is typically a part of the operating system. Wikipedia

Muxer

A multiplexer (or mux) is a device that selects one of several analog or digital input signals and forwards the selected input into a single line. Wikipedia

About

A method of maintaining FIFO order for related events while using a shared ExecutorService processor

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages