@backstreetbrogrammer
--------------------------------------------------------------------------------
Chapter 02 - Virtual Threads - Single Threaded Blocking OMS
--------------------------------------------------------------------------------
Suppose, we have an Order Management System (OMS) which is working as a TCP server and receiving stock trading orders from various clients.
Once the order is received, following processing is done on the Order object before it is sent down to algorithmic trading engine or directly to exchange (DMA):
Validate the order client's wallet if enough funds
Enrich the order with latest market data (best bid / best ask)
Update the latest order state to persistence (log or database)
This server is purely sequential and uses a single thread that does everything.
The thread is first blocked on accept(), listening for connections.
After a connection is established, that thread performs all the handling work before it can go back to listen and wait for more connections.
In the example code, each of the following takes around 1 second:
parse the request
create an Order from the request
validate the order client's wallet if enough funds
enrich the order with latest market data
update the latest order state to persistence
send the order to downstream
Therefore, it will take around 6 seconds to complete one request and send the order to downstream (if no error).
This also means that if three requests arrive at the same time, it will take 6 + 6 + 6 = 18 seconds to fulfill them at 6 seconds per request sequentially.
Github: https://github.com/backstreetbrogramm...
Upgrade to Java 21 Playlist: • Upgrade to Java 21
Apache Spark for Java Developers Playlist: • Apache Spark for Java Developers
Top Java Coding Interview Problems Playlist: • Top Java Coding Interview Problems
Java Serialization Playlist: • Java Serialization
Dynamic Programming Playlist: • Dynamic Programming
#java #javadevelopers #javaprogramming