Thread pools on the JVM should usually be divided into the following three categories:
- Blocking IO
- Non-blocking IO polling
Each of these categories has a different optimal configuration and usage pattern.
Let's take a simple example that models an employee along with the salaries accrued in a year. Here's the domain model in Scala:
case class Salary(empId: String, month: Int, amount: BigDecimal) case class Employee(id: String, name: String, salaries: List[Salary])
Yes, that’s right. It never makes sense to use foldl on lists because it never has any benefit and will always leak space.
To explain why, I wrote a mini blog post explaining the difference between foldl and foldr in Haskell. To start, you have to understand that foldl and foldr are not folds “from the left” and “from the right.” Both foldl and foldr traverse the structure in the same order, which in the case of lists means left to right. The difference is the fold’s associativity.
|Can we do it with `ClassTag` ?|
|You can't with a class tag, as it represents the erased type as known to the JVM. You could use a TypeTag|
|to reify the full type, but that depends on full scala reflection, which has its own downsides|
|(not thread safe, basically pulls in the compiler,...)|
|scala> import scala.reflect.runtime.universe.TypeTag|