Skip to content

Latest commit

 

History

History
49 lines (32 loc) · 2.64 KB

patterns.md

File metadata and controls

49 lines (32 loc) · 2.64 KB

Patterns

Diverse patterns with concurrency exists like:

  • Producer-Consumer
  • Distributed Locking
  • Object pool

Producer-Consumer

This is one of the main pattern which is used for explaining the thread approach. It can be implemneted in different ways like:

Object-Class

Low-Level API implementation. This pattern is implemented without any concurrency collections or special objects. Only the methods of the Object-class are used like wait, notify and notifyAll.

BlockingQueue-Class

High-Level API implementation. This pattern is implemented with BlockingQueue which are thead safe and are part of the java.util.concurrent package.

Distributed Locking

This kind of pattern is needed when you have different groups of threads which are bound to one lock.

Through a HTTPServlet many requests inbound and contain parameters which can be distilled as unique id, means the incoming request can be grouped by thouse ids. But only one request of a group should run a particular piece of code while the other requests with the same id should wait. This can be relaized only by manging multiple locks, each lock presenting an group of threads. I call this approach Distributed Locking.

This approach is a candidate for an extra implementation as part of the of the concurrency package.

One possible solution using the low level api with wait and notify can be found in the next example:

Object pool

Object pool is not a classic multithreading pattern. It is listed here because for implementing it, concurrency proramming needs to be used. This approach was listed in the project about software design patterns: