JSF-受管Bean中的对象列表和内存管理问题 [英] JSF - List of objects in a Managed Bean and memory management question

查看:65
本文介绍了JSF-受管Bean中的对象列表和内存管理问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建我的第一个JSF应用程序.对于这个问题,我将简化所有尝试,以使我的问题尽可能清楚.

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.

所有这些信息都存储在 ContactManager.java 托管Bean中.联系人上的所有数据都显示在数据表中.因此有一个地址数据表,电话数据表,上载数据表.每个数据表视图都位于适当的选项卡中.我正在使用Primefaces创建选项卡.因此,基本上,当打开一个联系人时,系统必须加载大约10个数据列表以及用于选择值的下拉列表.在选项卡中填充这些数据表.

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.contactId);
             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?

如果我有10个用户,并且他们都在查看具有大量数据的非常大的表的联系人,我担心这会使一切陷入瘫痪.

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.

我正在使用JSF 2.0/Primefaces 2.2RC2-Snapshot

I am using JSF 2.0 / Primefaces 2.2RC2-Snapshot

推荐答案

如果表很大,则无论有无JSF,服务器端都需要大量内存.

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

请勿使用富人脸表格;使用ui:repeat并为其编写自定义分页.

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

primefaces表优于h:dataTable或rich:datatable.

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

JSF 2.0为每个用户使用的内存减少了50%.

JSF 2.0 uses 50% less memory for each user.

另外,使用@RequestScoped bean和ViewScoped;不要使用SessionScoped bean.

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

您还可以从Faces上下文中的会话中删除会话Bean.

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");

等等.

此外,如果您在页面中有一些要存储的ID,并且您认为不能使用RequestScoped bean,那是错误的 与您的应用程序tomahawk myfaces集成,并使用t:saveState value =#{bean.categoryId}"/>

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}"/>

它是当前页面范围内的商店ID或对象,列表映射.

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

这篇关于JSF-受管Bean中的对象列表和内存管理问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆