Mutex in C++ and Java

Summary In this post, I will introduce the correct way to use mutex in C++, compared to Java. Conclusion Try not to use std::mutex directly. Use std::unique_lock, std::lock_guard, or std::scoped_lock (since C++17) to manage locking in a more exception-safe manner. Undefined behaviors will happen if a). A mutex is destroyed while still owned by any…

DependencyManagement and Dependencies in Maven

Summary In this post, I will introduce the key difference between Maven’s <dependencyManagement> and <dependencies>. Conclusion In pom inheritance, artifacts specified <dependencies> will ALWAYS be included as a dependency of the child module(s). However, artifacts specified in <dependencyManagement> will only be included if child modules explicitly specify them in <dependencies>. <dependencyManagement> is good for centralized…

Generics in Java Compared to C++ Templates

Summary In this post, I will introduce Generic in Java. The post may be useful when you are working with Java with prior knowledge of C++. Context The context is that I want to define an AbstractBaseClass which is a top-level abstract class but different subclasses require different types of arguments for some member functions….