0
votes

There is a large JSF application used by several simultaneous users.

The application gets PemGem space errors, increased use of CPU (mostly due to gurbage collection) and increased utilization of RAM. We need to optimize the code-base among several other measures to overcome these issues.

The application uses few common functions extensively. I want to know which is the best place to include such functions to optimize memory and CPU usage.

Example Function (We can simply convert these to static functions if necessary)

public long calculateAgeInDays(Date dob, Date toDate) {
    if (dob == null || toDate == null) {
        return 0l;
    }
    long ageInDays;
    ageInDays = (toDate.getTime() - dob.getTime()) / (1000 * 60 * 60 * 24);
    if (ageInDays < 0) {
        ageInDays = 0;
    }
    return ageInDays;
}

What is the best place to include these very common functions.

  1. EJB - Singlton
  2. EJB - Stateless
  3. JSF Managed Beans (Controllers) - Application Scoped
  4. JSF Managed Beans (Controllers) - Session Scoped
  5. JSF Managed Beans (Controllers) - Request Scoped
  6. Simple Java Class

Thanks in advance

1
I doubt this will have a positive impact on performance. Did you profile your application? On thing that helps is having complex EL converted to functionality in getters in beans and doing that 'lazy' so they are evaluated only once. - Kukeltje

1 Answers

1
votes

I would keep methods like these as static methods in Util classes. No reason for them to be kept as part of EJB or JSF beans if they are used extensively throughout application. Not sure, though, about the impact it will have on performance.