how to easily develop a non-blocking concurrent application ?
Most programmers are good at a synchronous mode that be executed sequentially in a thread, In a blocking system, wait thread is idle but continue to consume system resources.
here is a formula for high transaction volume:
Blocking system is running under a very ineffective mode. No high throughout, no high CPU load.blocking is not fit for multi-core CPU, and it is cancer that will kill the system later.
when we read data from socket by this way:
To avoid synchronous lock and blocking, we need use "volatile" or "Visibility" and "immutable", they are maybe difficult for most programmers.
A good way for non-blocking concurrent is queue of no lock, not JDK's BlockingQueue , the RingBuffer of Disruptor is a no-lock queue that can be shared between two threads. Actors mode is another non-blocking concurrent , it shares nothing.
In a non-blocking concurrent system: make a call which returns a result. don't need to use the result until at a much later stage of your process. don't need to wait immediately after making the call, instead you can proceed to do other things until you reach the point where you need to use the result. the call itself will return a "future" handle immediately. The caller can go off doing other things and later poll the "future" handle to see if the response if ready.
We can use Domain Events wrapping the RingBuffer of Disruptor, so threads communicates through events or messages, so no shared state, nothing to synchronize.this is Message-Passing Concurrency.
we design Message-Passing Concurrency into open source jdon framework.
the non-blocking concurrent way of jdon framework is here: Domain Model sends events to another thread(a consumer) by RingBuffer in Disruptor, so two threads can communicates through event ;After the consumer done, it will put the result in another RingBuffer that publisher can read or blocking read it, decided by business is or not executed sequentially.
by domain events and DCI in jdon framework we make an exploratory to promote non-blocking concurrent programming paradigm. jdon framework can help most programmers quietly going to the way of non-blocking concurrent programming when they thinking in DDD.
DCI and Domain Events are different abstract high levels based concurrent programming, DCI is easier to be understand than Domain Events , DCI and UML colors analysis method can successfully docking, it is the highest level of abstraction of business-oriented.
here shows how to use DCI and Domain Events in jdon framework :
If we already hold on a model object, we can implements various functions by its domain events,such as modify/update a model.Otherwise:We create a context, and there we inject events or functions into a new model object by RoleAssigner,such as create or delete a model.
details in :