Your system just does some basic work. It doesn t involve big objects or long-lived objects. But you may still need a bigger heap if It frequently creates many short-lived objects. One example is logging. Some logging libraries may create tons of byte[] objects, such as logback 1.2.x So why is a bigger heap needed? Because A high-throughput Java OLTP system may need a bigger heap Read More
Say there is 1 request dispatcher and multiple request consumers. If they share the same thread pool, then the request dispatcher may starve because request consumers may be hogging too much of the threads. If the request dispatcher starves, requests will be flowing into the system at a lower rate. And then your request consumers Let request dispatcher have its own thread Read More
Instead it s based on position. To be specific, the first column in the select sql will be mapped to the first property of the case class. Here is an example: Let s say in the db there is a table called foo_bar foo bar fff bbb This is not desirable. But the author of Doobie won t Note: Doobie s row->case class mapping is not based on case class property name Read More
It s said IO.pure() means eager evaluation. But it doesn t seem to so in this example: Here println("print in pure") is executed just like as if it s IO.apply() Another example, however, discloses the truth Here is it how it works: When printTwice() is called, every expression inside it is evaluated IO.apply(println("print in lazy")) is evaluated as In Cats-effect, when is xxx inside IO.pure(xxx)…
Exceptions thrown in a task submitted to a thread pool will just disappear. You won t even see the log. You can catch java.lang.Exception and handle it. But to make things even better, please catch java.lang.Throwable instead. In theory, it s not recommended to catch a Throwable. But to be pragmatic, it s important for you to see Please catch Throwable in a task submitted to a thread pool Read…
There are a few strange things about Condition related code in Java concurrency. I ll use the following code to show you. The code is about one cup and two threads. One thread is trying to fill it, the other to drink from it. The code uses explicit Lock + Condition API. But what I m going Condition variable related code is hard to understand. So let me explain Read More
What does the primitive do? Increase an integer value by 1 Return the original value It s a hardware primitive, hence atomic. It can be used to implement a ticket lock. How it works Say t0, t1, t2 both arrives at line 12 Since FetchAndAdd() is atomic, the changes made by threads are serialized. Let s assume Fetch-and-add Primitive and Ticket Lock Read More
First of all, it s not the same as compare-and-swap . Sounds similar, but different. What it does is, Set a variable to a new value Return the old value of the variable It s a hardware primitive, i.e. atomic. On x86 the instruction is `xchg` (There is actually no test , is there? ) What can it Test-and-set Primitive Read More
Lock stripping: Use different locks for different purposes on the whole data structure. For example, a read lock + a write lock Lock splitting: Use multiple locks for different parts of a data structure. For example, 16 locks are used for a ConcurrentHashMap, each guards N/16 buckets (N = total number of buckets)