JSF - 托管 Bean 中的对象列表和内存管理问题
我正在创建我的第一个 JSF 应用程序。对于这个问题,我将简化一切,以使我的问题尽可能清晰。
我正在创建的应用程序是一个简单的联系人存储应用程序,它允许您创建新联系人、存储地址、电话号码、工作地点等信息,以及上传与该联系人关联的文件。
当应用程序加载时,将向用户显示已创建的联系人列表。他们可以单击联系人的图像来打开联系人并查看其中存储的所有信息。这就是我的问题所在。
所有这些信息都存储在 ContactManager.java 托管 bean 中。联系人的所有数据都显示在数据表中。所以就有了地址数据表、电话数据表、上传数据表。每个数据表视图都驻留在适当的选项卡中。我正在使用 Primefaces 来创建选项卡。因此,基本上,当打开联系人时,系统必须加载大约 10 个数据列表以及用于选择值的下拉列表。在选项卡中填充这些数据表。
@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);
}
}
}
因此,基本上,当用户打开联系人时,所有联系人信息都会加载到内存中,以便可以在视图中显示。
这个示例对于我存储的列表和数据的实际数量来说很小,但为了简化起见,我想知道内存管理。
我的系统将被许多用户使用,加载所有这些信息让我担心。为所有这些分配的内存何时被清除?我有责任清理吗?
如果我有 10 个用户,并且他们都在查看包含大量数据的非常大的表的联系人,我担心这会让一切陷入停滞。
目前它在我的系统上运行良好,但我知道所有这些表格和列表都保留在内存中,直到用户单击并打开新联系人或关闭应用程序。
任何关于这是否是正确的做事方式或如何处理这样的大信息的见解都会很棒。
我正在使用 JSF 2.0 / Primefaces 2.2RC2-Snapshot
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.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?
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果表很大,则无论有或没有 JSF,服务器端都需要大量内存。
不要使用丰富的面孔表;使用 ui:repeat 并为其编写自定义分页。
primefaces 表比 h:dataTable 或 rich:datatable 更好。
JSF 2.0 每个用户使用的内存减少了 50%。
另外,使用@RequestScoped beans和ViewScoped;不要使用 SessionScoped beans。
您还可以从面孔上下文中的会话中删除会话 bean。
等等。
另外,如果你在页面中有一些用于存储的id,并且你认为你不能使用RequestScoped beans,那么这是错误的
与您的应用程序 tomahawk myfaces 集成,并使用 t:saveState value="#{bean.categoryId}"/>
它是在当前页面范围内存储 id 或对象、列表映射。
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.
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.