Posts

Push Notifications

Image
A notification in a message you can display to the user outside of your application's normal UI. When you tell the system to issue a notification, it first appears as an icon in the  notification area . To see the details of the notification, the user opens the  notification drawer . Both the notification area and the notification drawer are system-controlled areas that the user can view at any time. System will also display the notification as a TOAST when user is logged-in along with increment in the notification drawer. Lightweight Event Driven Notification System 1.1      Event Generation The event generation phase happens while processing the response to a user request. As such, we wanted to ensure that there was little or no impact on the response times from where notification is called/generated. To ensure this was the case, all we will do is store the minimum amount of data possible/lightweight message on the queue. We store the min...

Multi-Files-Parser

Multi-File Parser is having ability to parse XML, JSON, XLS and CSV. It is written on top of various industry standard parsers. The API is  simple to use , independent in nature and is written to  perform and scale . It is written using Strategy so new strategies i.e. Parsers for new formats can be added adhering Single Responsibility. Ability to read files from a directory or File[]. Supports paralellism i.e. processes files in parallel using Java 7 Fork/Join. Easy data validation support using JSR-303 Bean Validation annotations. Uses Notification Pattern ( bliki ) for validation errors. Spring Support ##Usage Simple usage with a single line of code. Example XML Parse Example.  Check for all examples in [test] ( https://github.com/dapinder-dhillon/Multi-Files-Parser/tree/master/src/test ) folder   @Autowired private DataFeedController dataFeedController; .... .. Map rtnObj = dataFeedController.process(Records.class, sourceDir, FeedSupportedFileT...

Creating your Cache with LRU Algorithm

The LRU caching scheme is to remove the least recently used frame when the cache is full and a new page is referenced which is not there in cache. Please see the Galvin book for more details. This class defines a simple cache entry for the cache. A cache entry holds cached object along with some metadata attributes. These metadata attributes assist in managing the cache. These cache entries are not serializable and thus these are not  cluster aware. This is a simple hash map based cache with LRU cleanup algorithm. CacheEntry.java package com.dapinder.example.own.cache; public class CacheEntry { //the object that is saved in this cache entry private K cachedObject; //the time when the cached object was accessed or modified last time. private long lastAccessTime; /** * This returns the object stored in a cached entry. * * @return the cachedObject */ public K getCachedObject() { lastAccessTime = System.currentTimeMillis(); return cachedObject; ...

Magical Final - Expanded Usage

Image
Most of us are aware of keyword final in java for the following: Prevent Inheritance by declaring class as final. Prevent method overriding by making method as final. Declaring constants. I am here to let know more advantages of keyword 'FINAL' which are not generally aware of: More about Final Constants. Conditional Compilation More About Final Constants Primitive (int, char, float etc) other than arrays are substituted at compile time with their values, if you change a final that is used by other classes, you must remember to recompile those other classes or your change will not take effect. The same rule applies to constants of type java.lang.String . Although String is a constructed type, it is also substituted at compile time. All constructed types other than String , mutable or not, are not substituted at compile time. To understand how this works Consider the following code fragment: package com.dapinder.practice; public class FinalCo...

Heap Dump Analysis

Image
When I got an OOM (out of memory) error, I had to try and understand what was going on inside the JVM. The best way to do that is a heap dump. The general idea is to dump out the contents of the JVM’s memory into a file, then analyse it using a tool.  An OOM simply means that the JVM ran out of memory. When this occurs, we basically have 2 choices: Allow the JVM to use more memory i.e. increase the –Xmx. But the question is till what extent? Improve/Fix the application so that it uses less memory. A memory leak happens when the application keeps more and more references to objects and never releases them. The garbage collector will therefore never collect those objects. At this point, the JVM will throw an OOM. To solve this issue, we first need to find the root cause of it. Java has a built-in feature for dumping heap snapshots called HeapDump. What is a heap dump? A heap dump is the dump of the heap. It will allow us to navigate the heap and see what objects u...

Understanding OutOfMemory Issues

Image
One of the most common problems that beset enterprise applications is the dreaded OutOfMemoryError. The error is typically followed by one of the following: Either you application server crashes. Or you have severe performance bottleneck.   A stuck thread waiting on resources leading nowhere and ultimately crashing the server. Regardless of the symptoms, you will most likely need to reboot the application server to make think ok. Causes of out-of-memory errors Before you attempt to resolve an out-of-memory error, first understanding how it can occur is beneficial. If the JVM runs out of memory anywhere in its process memory space, including all regions in the heap as well as the permanent memory space, and a process attempts to create a new object instance, the garbage collector executes to try to free enough memory to allow the new object's creation. If the garbage collector cannot free enough memory to hold the new object, then it throws an OutOfMemoryErro...