开发者

JSF - List of objects in a Managed Bean and memory management question

I am creating my first JSF application. For this question I am going to simplify everything to try and make my question as clear as possible.

The application I am creating is a simple contact storing application that will allow you to create a new contact, store information such as addresses, phone numbers, where they work, and upload files that are associated to the contact.

When the application loads the user is displayed with a list of contacts that have already been created. They can click on the contact's image to open up the contact and view all of the information stored on them. This is where my question comes in.

All of this information is stored in the ContactManager.java managed bean. All of the data on the contact is displayed in datatables. So there is an address datatable, phone datatable, uploads datatable. Each datatable view resides within an appropriate tab. I am using Primefaces to create the tabs. So basically when a contact is opened the system has to load maybe about 10 lists of data as well as dropwdown lists used for select values. to populate these datatables in the tabs.

@ManagedBean
@ViewScoped
public class ContactManager implements Serializable {

     private Contact contactInfo;
     private List<Phone> phones;
     private List<Addresses> addresses;
     private List<Company> jobs;
     private List<Files> uploads;

     //dropdown select lists
     private List<Country> countryList;
     private List<State> stateList;

     //Getters and setters for everyting
     ..... (I am not going to type it all out but its there)


     @PostConstruct 
     public void openContact() {
         try {
             this.countryList = myDao.getCountryList();
             this.stateList = myDao.getStateList();
             this.addresses = myDao.getAddresses(contactInfo.contactId);
             this.phones = myDao.getPhones(contactInfo.conta开发者_如何学运维ctId);
             this.jobs = myDao.getJobs(contactInfo.contactId);
             this.uploads = myDao.getUploads(contactInfo.contactId);
         }
     }  
}

So basically when a user opens a contact all of that contact information is loaded into memory so it can be displayed in the view.

This example is small to the actual amount of lists and data that I am storing but for simplification sake I am wondering about memory management.

My system is going to be used by a number of users and loading all of this information worries me. When does the memory allocated for all of this get cleared? Am I responsible for clearing it?

If I have 10 users and they are all viewing contacts that have really big tables with a lot of data I fear that this is going to bring everything to a standstill.

Currently it runs fine on my system but I know that all of these tables and lists are kept in memory until either the user clicks and opens a new contact or closes the application.

Any insight on if this is the right way of doing things or how to handle large information like this would be great.

I am using JSF 2.0 / Primefaces 2.2RC2-Snapshot


If the tables are big, you need a lot of memory on server side, with or without JSF.

Do not use rich faces tables; use ui:repeat and write custom paging for it.

primefaces tables are better than h:dataTable or rich:datatable.

JSF 2.0 uses 50% less memory for each user.

Also, use @RequestScoped beans and ViewScoped; do not use SessionScoped beans.

You also can remove sessions beans from session from faces context.

context = FacesContext.getCurrentInstance();
externalContext = context.getExternalContext();  
externalContext.getSessionMap().remove("UserContext");
externalContext.getSessionMap().remove("SessionController");

Etc.

Also, if you have some id for store in the page and you think you can not use RequestScoped beans, it is mistake integrate with your application tomahawk myfaces, and use t:saveState value="#{bean.categoryId}"/>

it is store id or objects, list maps, in the current page scope.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜