Show TOC

Background documentationInitializing and Destroying Portal Components Locate this document in the navigation structure

 

This section provides guidelines for reducing the startup time of a portal application, and for initializing and destroying portal applications.

To reduce the startup time of the application:

  • Do not initialize complex parts of the application, which are not used in the initial view, before they are requested by the user.

  • Implement lazy loading for portal services or at the application level, to avoid loading an object before it is needed.

In the initialization phase of a portal application, initialize and allocate runtime resources once for the entire request cycle, to avoid allocating these resources for each individual request. In the destruction phase of a portal application, free all runtime resources allocated in the initialization phase.

To ensure proper initialization and destruction of the portal components and portal services, implement the initialization and destruction methods, init() and destroy(), as shown in the following example.

Example Example

This code snippet is part of a portal service that authenticates users using a user list in the file system.

Rather than loading the entire user list each time it is necessary to authenticate a user, the implementation loads the user list once at the initialization stage of the application. In this manner, authenticating a user requires only an in memory calculation. The destroy API is also used at the end to nullify the user list object.

End of the example.

Syntax Syntax

  1.   public class UserAuthenticationService implements IUserAuthenticationService{
    
      private IServiceContext mm_serviceContext;
      private Properties userList;
    
    public void init(IServiceContext serviceContext)
      {
        mm_serviceContext = serviceContext;
        userList = new Properties();
          try 
          {
                userList.load(new FileInputStream("\\user_list.properties"));
          } catch (Exception e) {
                return;
          } 
      }
    
      public boolean isUserAndPasswordValid(String user, String password) 
      {
          return password.equals(userList.getProperty(user));   
      }
    
      public void destroy()
      {
            userList = null;
      }
    
End of the code.

Note Note

The code snippet uses a portal service. The same approach can be applied to portal components using the following methods:

  • public void init(IPortalComponentInitContext context)

  • public void destroy()

End of the note.