Wednesday, September 19, 2018

How to calculate memory used by an object

this article required classmexer.
before start make sure download the classmexer dependency from here or classmexer 0.0.3.

1. extract and put the classmexer.jar in classpath.
2. call classmexer api to calculate memory usage.


Product p= retrieveProductFromDB();


System.out.println("Size of product is " + MemoryUtil.deepMemoryUsageOf(p));

System.out.println("Size of product is " + MemoryUtil.deepMemoryUsageOf(p, VisibilityFilter.ALL));

System.out.println("Size of product is " + MemoryUtil.memoryUsageOf(p));



Done!!

Thursday, May 24, 2018

Multiple phases commit


psedocode
client invokes System A
  System A performs process
  if success
    System A commits
    System A invokes System B
    System B performs process
    if success
      System B commits
      System B invokes System N..
      System N.. performs process
      if success
        System N.. commits
      else
        System N.. rollback
        System N.. return false
    else
      System B rollback
      System B return false
  else
    System A rollback
    System A returns fail


to simplified the above logic,
1.    process and commit own transaction.
2.    invoke external system/process
3.1 if success, return true
3.2 if failed, return false, manual rollback the transaction.


Done!!


Wednesday, May 16, 2018

Manual rollback with MongoDB

When there is a need to save different documents at the same time in microservices, or more specifically NoSql.
It is not an easy job, because NoSql does not support transaction like RDBMS.

The multiple phases commit in the previous post able to achieve the transaction-like behavior with MongoDB.

The code snippet below will be demonstrated by Play2.x, MongoDB, Morphia.


JsonNode json = request().body().asJson();
MyDocument md = Json.fromJson(json, MyDocument.class);
MyDocument mdCurrent = MyDocumentRepo.findMyDocumentById( md.getId() );

MyDocumentRepo.save( md );

boolean status = callNextService();

if(status == true) {
  // not doing anything
} else {
  // manually rollback the previous md
  MyDocumentRepo.save( mdCurrent );
}



Done!!

Tuesday, May 15, 2018

How to change font in Oracle SQL Developer

Tools > Preferences... > Code Editor > Fonts

edit the Font Name, Font Size
Click OK.


Done!!

Sunday, March 4, 2018

java.lang.ClassCastException: $ProxyXX cannot be cast to xxx

When a system using EJB encountered a ClassCastException: $ProxyXX...
this could be due to same mappedName in the same system.

@Stateless(name = "MyBusinessObject", mappedName = "MyBusinessObject")

Therefore, when the system encountered the above exception,
the developer needs to check whether the class throwing the above exception mappedName also used in other class.


Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...