java - Difference between Producer/Consumer pattern and Observer Pattern -


i understand difference between observer pattern , common problem of producer/consumer , since both require synchronization changes available , , how go implement both ( if different )

the difference between them nature of synchronization required.

in case of observer pattern whenever change of interest made in observed object observers notified immediately. immediate per change synchronization required pattern. in fact observer patterns doesn't require different thread. thread changing observed object can notify registered observers.

however, in case of producer-consumer required synchronization consumer must wait when there no element , producer must wait when buffer full. per object synchronization not required. producer can produce multiple objects before consumer consume of them , consumer can consume multiple objects in 1 go. immediate notification observer not needed here.

as far implementation, can have @ wikipedia articles them: observer pattern , producer-consumer problem.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -