Powered by Blogger.

4.2. Design Patterns

>> Monday, June 8, 2009

Design patterns are set of rules which come as best solutions for reoccurring problems of application development.
Design patterns are the best practices to use software technologies in application development.
Design Patterns:

1.Singleton java class:
Java class that allows to create only one object per JVM is called Singleton java class.
  • Instead of creating multiple objects of a java class having same data. It is recommended to create one object per JVM and using for multiple number of times. This process reduces memory wastage.
  • In MVC architecture based application there must be only one servlet class object acting as Controller. So ActionServlet which is built in ControllerServlet of struts based web applications is given as Singleton java class.
  • Every servlet is a single instance multiple threads components.That means when multiple requests are given to servlet class only one object of Servlet class will be created and multiple threads will be started on that object representing multiple requests.
Q: Servlet(ActionServlet) is a single instance, multiple threads component. Then what is the need of designing ActionServlet as Singleton Java class.?

A: ActionServlet is a built in servlet given by struts Framework spftware as singleton java class.

  • Some web containers of webservers/application servers are violating servlet api-specification principles by creating multiple objects for servlet class in some special situations.
Ex: If a servlet deployed in weblogic server gets more than 300 requests at a time or simultaneously, the web container of weblogic creates second object of servlet class. This i simply violation of servlet specification rule called that servlet is a single instance multiple thread component.

When struts application is deployed in these special servers in order to see only one object of ActionServlet is given as singleton java class.

A Servlet is identified through its url-pattern. We can use one of the three approaches to provide url-pattern for a Servlet.
 

1.Exact match:
other matchings:

<url-pattern>/first</url-pattern>
<url-pattern>/first.xyz</url-pattern>

Example url : (valid)
  • http://localhost:8080/wa1/first/xyz
Example url : (invalid)
  • http://localhost:8080/wa1/xyz/first
  • http://localhost:8080/wa1/xyz
  • http://localhost:8080/wa1/first
  • http://localhost:8080/wa1/abc
  • http://localhost:8080/wa1/first/xyz/abc
Note: In Exact match url-pattern * (star) symbol will not be there.

2.Direct match:
  • Direct match url pattern ends with * symbol.
  • url-pattern is to provide the secrecy to servlet by hiding their names.
Example urls(valid):

http://localhost:8080/wa1/x/y/abc
http://localhost:8080/wa1/x/y/z/abc
http://localhost:8080/wa1/x/y/
http://localhost:8080/x/y/xyz/a/b/abc
Example urls(invalid):

http://localhost:8080/wa1/y/x
http://localhost:8080/wa1/a/b/x/y/abc

3.Extension match:
Extension match url-pattern starts with '*' symbol.

Example urls (valid) :

http://localhost:8080/wa1/x/y/z.cpp
http://localhost:8080/wa1/x/y.cpp
http://localhost:8080/wa1/.cpp

Example urls (invalid) :

http://localhost:8080/wa1/a/b/c.cpp/x/y
http://localhost:8080/wa1/x/c.abc

Any extension will be given but it has to match the given URL pattern extension.

We can't frame URL-pattern by mixing up extension match and directly match.Because the underlying web server does not recognize this kind of URL-pattern . Because it is against servlet specification.

Related Posts Plugin for WordPress, Blogger...
© javabynataraj.blogspot.com from 2009 - 2022. All rights reserved.