SERVLET.BINS
Avoid using java.beans.Beans.instantiate ()
Description
This rule flags code that uses java.beans.Beans.instantiate ().
This method will create a new bean instance either by retrieving a serialized version of the bean from disk or by creating a new bean if the serialized form does not exist. The problem, from a performance perspective, is that each time java.beans.Beans.instantiate is called, the file system is checked for a serialized version of the bean. Such disk activity in the critical path of your web request can be costly.To avoid this overhead, simply use "new" to create the instance.
Example
package SERVLET;
import javax.servlet.http.*;
import java.beans.*;
public class BINS extends HttpServlet {
public void doGet (HttpServletRequest rquest)
throws ClassNotFoundException, java.io.IOException {
Beans ab = (Beans) Beans.instantiate (
this.getClass ().getClassLoader (),
"web_prmtv.Bean");
// do something...
}
}
Repair
Use new someClass () to create a new object instance.
public void doGet (HttpServletRequest rquest)
throws ClassNotFoundException, java.io.IOException {
Beans ab = new Beans ();
// do something...
}
Reference
IBM WebSphere Application Server Standard and Advanced Editions, Harvey W. Gunther.
http://www-4.ibm.com/software/webservers/appserv/ws_bestpractices.pdf
|