Use Singleton Objects to Reduce Garbage Collection

Performance tuning of Servlets is a major criteria as a servlet is expected to simultaneously handle dozens, if not hundreds, of threads depending on the requests. These coexisting threads have to share the resources of the JVM. One way to tune the performance of the Servlets is to use Singleton Objects. This results in a single object once declared, being used by all threads. This ensures that a new object won’t be created for each thread, resulting in Garbage Collection once the object goes out of scope. Garbage Collection is a very huge operation and every time it runs, it is a major overhead to the efficiency of the servlet.

Another alternate solution can be static objects which can again be used without creating objects and thus reducing the work of the Garbage Collector.

Example of a singleton object:

 public class SingletonTrial{ // Privatize the constructor so that no other class can call it. private SingletonTrial() { }  // Create the only instance of SingletonTrial Object private static SingletonTrial instance = new SingletonTrial();  // Make the only static instance publicly available public static SingletonTrial getInstance() { return instance; } } 
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS