Friday, July 28, 2017

Java - Calculate Total Time Elapsed using Java5 or higher

Java - How to calculate the total Time elapsed for a java method.

It is a standard requirement in a lot Java components/applications to find out the total time a method has taken to execute the call.

Though there are several 3rd party libraries (Spring MethodInterceptor,  java-InvocationHandler/DynamicProxy, and AspectOrientedProgramming) that offer method interceptor feature where the time can can be tracked.
Looking at greater need of this requirement of calculating precise time (NanoSeconds..) that a method spent on, Java5 has introduced a new TimeUnit class.

Please see below example for reference

public static String calculateTotalTimeElapsed(long startNanoSec, long endNanoSec) {
long difference = endNanoSec - startNanoSec;
String totalTimeString = String.format("%d Hours, %d Min, %d Sec, %d Millis, %d Micro, %d Nano",
TimeUnit.NANOSECONDS.toHours(difference), TimeUnit.NANOSECONDS.toMinutes(difference),
TimeUnit.NANOSECONDS.toSeconds(difference), TimeUnit.NANOSECONDS.toMillis(difference),
TimeUnit.NANOSECONDS.toMicros(difference), TimeUnit.NANOSECONDS.toNanos(difference));
return totalTimeString;

       public static void main(String args[]){ 
               long timeBefore1 = System.nanoTime();
               //TODO: call any other function (db or resource intensive)
               String timeString = calculateTotalTimeElapsed(timeBefore1, System.nanoTime());
              System.out.println("Method has taken  "+timeString);

o Hours, 1 Min, 2 Sec, 400 Millis, 298 Micro, 12345 Nano.

Thursday, May 4, 2017

My Desktop background

Recently I've been thinking to come up with collection of best quotes that can keep reminding and motivating me everyday at work.

As Health, Finance and Career are my current priorities, I've come up with the following collection.

Feel free to use if you like.

Thursday, April 13, 2017

My view on Microservices Architecture (MSA)

It is a new architectural pattern to Design & Develop application(s) into smaller and manageable modular services that can be built using APIs/services with modern languages/frameworks. 

Though this is more popular and fashionable idea, is not a very new in Architects and Designers world when creating large and monolithic application. They have been contemplating to adopt this to build more scalable and maintainable solutions. Their thoughts were always limited by the availability of tools and technologies for implementation and new operational complexities.

Why MSA and What is the reason behind the popularity?
  • The emergence of lightweight REST integration (API Management) over popular SOAP (SOA-ESB) systems.
  • The emergence of new languages/technologies/frameworks that allow a few solutions can be developed with modern languages/frameworks. The replacement of these solutions can also be built more quickly if they are not addressing the requirements.
  • DevOps: Advancement in hardware where a software (Hypervisor) can be used to automate infrastructure, scaling the instances as needed and utility computing. 
  • Virtualization and Docker/Container management.
  • Change in how systems are communicated with Datastore, As there are more reads of data over writes; the gaining popularity of CQRS (Command Query Responsibility Segregation) with Event Sourcing over CRUD (Create Read Update and Delete) operations.
  • Emergence of new DBMS systems (RDBMS, SQL, NO-SQL, Graph SQL) etc..
  • Different interfaces (Desktops, Hand held devices with Mobility) to access the solutions with different user experience built on the same back-end solutions.
  • Growing popularity in Systems working on Distributed Architecture.
The API brings standardization of service development and its accessibility.
It promotes to develop, build and deploy the pieces (modules) of software independently and also offers scalability in deployment.
It is also a new architecture & design style to migrate Monolithic application (one big single application with lot of components without modularity) into more smaller services that are designed, developed, built and deployed independently.
It offers re-usability of these smaller modules (services) as this is essential to Enterprise with shared services organization.
It prefers BASE (BasicallyAvailable, SoftState and Eventually Consistent) transactions over ACID (Atomicity,Consistency,Isolation, Durability) in Distributed Architecture.
It prefers CQRS (Command Query Responsibility Segregation) with ES (Event Sourcing) over CRUD operations as there are more Reads than Writes.

Problems of Monolithic:
Code complexity and maintainability
Deployment becomes the bottleneck
Fear to change once the asset is grown big enough to make changes and regression-impacts.
Lack of ownership as it is
One size doesn’t fit all (ex: relational DB)
Hard to scale out, though limited scale up is possible.

Benefits of Microservices:
  • Speed
    • Faster development and deployment
    • Polyglot
  • Innovation
    • Autonomy of teams, culture of change
    • Ownership and DevOps culture
  • Quality
    • Reusability & more maintainable code
    • Better scaling and optimizations
    • Failure Isolation and Resilience
  • Overhead or Complexity of Communication in Development, Deployment and Operational Management. Some Cloud vendors (AWS) have addressed some of these solutions with tools.
  • Fairly new concept. Challenges in Finding experienced resources in market and Enterprise adoption.
  • Change of mindset is required to adopt to realize the benefit on ease of doing.
  • Technology stack is evolving fast: Determining when they are ready for Enterprise.
  • Investment overhead of both new API and ESB in large enterprises.
Though the Tier-1 technology companies (ex. FAANG) which can repeatedly re-invest in re-writing their popular solutions on new and modern architectures to offer new experience to customers, it is fair to say that the Tier-2 and organizations where IT is supporting the other business would mostly wait and see until the tools and practices are stable and technology becomes enterprise ready.

The startups and smaller organization can always venture into as their size, existing and limited investments would allow them to invest in these new areas.

Thursday, March 23, 2017

Plan for TOGAF9.1

Plan for TOGAF 9.1

Preparation Resources:
  1. Read preparation plan at
  2. Read others experience from
  3. Read preparation from
  1. Materials  from    
  3. Read the 'ADM cheat sheet' of 'Scott Duffy'  PDF.  Sign up for free PDF at
  4. Cheat sheets (2) from    a.
  5. Go through
  6. Check Resources  section/table at
  7. TOGAF input/output PDF at
  8. Read the TOGAF official document from OpenGroup.
  9. Read Exam study Guide at
  10. Go through
  11. Go through
  14. Read the MindMap 
  15. Buy the PART 1 course at and download all Videos.
  16. Buy the PART 2 course at and download all Videos.
Mock Exams:
  1. Mock Exam at
  2. Mock Exams at
  3. Mock exams at
  4. Mock exams at

  5. Sample Exams from
  6. Go through TOGAF 9 Scenario questions:
  7. Go through TOGA 9 sample questions at

Private Repositories, Not available to Public
 Modeling Tools:
  1. EA  at
  4. Abacus at