devxlogo

Threading

Image

Do Not Assume SimpleDateFormat Is Thread-safe

The code below is improper because it shares a static instance of a SimpledateFormat with any possible number of threads. Public class Constants { Public static final SimpleDateFprmat date =

Image

Keeping Tabs on all Threads in Your Environment

Oftentimes, you might want to understand and control all the threads in your runtime. Java provides an effective and easy mechanism to achieve this using Thread.activeCount() and Thread.enumerate() methods. public

Image

Finding the Count of All Active Threads

Most developers work with threads at one point or another. It can be important to know which threads are active to accomplish a given task. The following API activeCount on

Image

Using ThreadMXBean to Understand Threads

The java.lang.management.ThreadMXBean is an interface that helps us to understand a lot about Threads in our code. There are numerous methods that participate to provide excellent visibility of the Threads. Something

Image

Making a Java List Thread Safe

The java.util.list is not thread safe by default. There can be situations where you would want to use the list in a multithreaded environment for processing. An effective mechanism is