Managed-Bean best practice

2019-09-02 20:39发布

I'm back to building my Managed-Bean of a hashMap. ( Creating a HashMap of type <String , Object> ) I have defined a class

public class AppProperties {
    private String appRepID;
    private String helpRepID;
    private String ruleRepID;
    private String filePath;
    private Vector formNames;
    private Database appDB;
    // all the getters and setters
}

The managed bean will create an Application Scope variable of the hashMap. In the constructor of the Bean I build the the values for each Application (the key) by collecting all the info from a number of different places. The repIDs are pretty straight forward. My question/concern is it wise to store the appBD in the Application Scope variable. I have read that one should never store a Notes Object in a Scoped Variable would that be an issue here? Secondly, if that is the case I could add a method to the AppProperties that would open the DatabaseByReplicaID when ever the method to get the Application Database is called, which adds a fair bit of overhead to the process as the database object will get called many many time in the life cycle of the application.

标签: java xpages
1条回答
Viruses.
2楼-- · 2019-09-02 21:12

Right, you shouldn't store Notes objects in scope variables and properties of beans.

Because They are not serializable (a must for certain scopes) and they will be recycled between lifecycles. More precisely, since they are based on C-handles, XSP engine creates Notes objects between request-response cycle and when response written back to the user, they are all going to be recycled. Trying to keep them in the memory will make them 'toxic' for your server.

You can define a method in your bean (like GetHelpDb()), create and return it whenever you need. It's not a huge performance cost. Because Domino server implements caching for databases. When you open a database over and over again will not generate additional disk I/O.

The best practice for interacting with Notes data in such situation would be caching. I frequently use this approach in my applications. You might get values in a single method, cache them into HashMap(s) and get them from the map when you need. Using getter method, you may also check a time-based value to handle time-outs.

查看更多
登录 后发表回答