In my last blog, we explored WeakHashMap which is based by WeakReference in
Java. Now let's look at some best practices for using another powerful class:
ThreadLocal from java.lang, which is also implemented using WeakReference.
What is ThreadLocal? A simple example
As its name suggests, a single instance of ThreadLocal can store different
values for each thread independently. Therefore, the value stored in a
ThreadLocal instance is specific (local) to the current running Thread, any
other code logic running on the same thread will see the same value, but not
the values set on the same instance by other threads. (There are exceptions,
like InhertiableThreadLocal, which inherits parent thread's values by
Let's consider this example:
We have a TransactionManager class that provide static methods to:
Start a transaction with a generated ID Store that ID as a st... (more)
Solr Server provides JMX statistics that show performance details such as
query speed and cache hit/miss rates in a macro level, which James talked
about in a previous post. However, it might be tough to trace how a
particular operation; for example: how a specific query fared in the system.
This week, I'd like to introduce TraceView's latest support for Solr Server,
which provides breakdown of each operation, enabling more precise performance
monitoring and troubleshooting.
How does Solr work, anyway?
Requests made to Solr Server can be roughly divided into 3 categories:
When it comes to analyzing your web application's performance, TraceView
already has instruments in a wide spectrum of Java components, such as
application servers, frameworks and JDBC connections, all with the
convenience of simply including TraceView Java agent jar in your JVM.
However, have you come across situations that make you think, "It would have
been nice if this was traced too"? You can do this with the TraceView Java
Don't feel like coding? Just annotate it!
Have you seen a slowdown in your code, and have some methods you'd like to
check? The simplest way is t... (more)