Professional web hosting - HttpSession. In some cases, this might be the

HttpSession. In some cases, this might be the only way to achieve a particular requirement. However, you must consider the effect that storing objects and data in the session has on an application. The more information and objects that are stored in the session, the more you need to worry about scalability. Say that you store 0.5 MB worth of data for a single user. If the application were loaded with 1000 concurrent users, that would equal 500 MB (0.5 GB) worth of memory. Don’t forget that there are other resources taking up memory, not just user sessions. There’s application-scope data, the rest of the Struts framework, your application components, the container itself, the JVM, and so on. You must consider all of these factors. As you can see, using the session to store data can quickly eat up memory. A better alternative is to use the HttpServletRequest to temporarily store data that can be used by other components and then reclaimed by the garbage collector when the request is completed. With request-scoped data, the responsibility of cleaning up the data is between the container and the JVM, not the application. 17.5.2 Using the synchronized Keyword Synchronization is used to control the access of multiple threads to a shared resource. There are many situations where synchronization makes sense and is absolutely necessary to keep multiple threads from interfering with one another, which can lead to significant application errors. Struts applications are inherently multithreaded, and you might think that certain parts of the web application should be synchronized. However, using the synchronized keyword inside of your Struts applications can cause some significant performance problems and reduce the overall scalability of the applications. We’ve all heard at one time or another that servlets should not contain any instance variables. This is because there may be only a single instance of a servlet running, with multiple client threads executing the same instance concurrently. If you store the state of one client thread in an instance variable and a different client thread comes along at the same time, it may overwrite the previous thread’s state information. This is true for Struts Action classes and session-scoped ActionForms, too. You must be sure to code in a thread-safe manner throughout your application. In other words, you must design and code your application to allow for multiple client threads to run concurrently throughout the application without interfering with one another. If you need to control access to a shared resource, try to use a pool of resources instead of synchronizing on a single object. Also, keep in mind that the HttpSession is not synchronized. If you have multiple threads reading and writing to objects in the user’s session, you may experience severe problems that are very difficult to track down. It’s up to the programmer to protect shared resources stored in the user’s session. 17.5.2.1 Using java.util.Vector and java.util.Hashtable You must also be careful which Java classes you use throughout your Struts applications, especially when it comes to selecting a collection class. The java.util.Vectorand java.util.Hashtable classes, for example, are synchronized internally. If you are using Vectoror Hashtable within your Struts applications, this may have the same effect as using the synchronized keyword explicitly. You should avoid using these classes unless you are absolutely sure that you need to. Instead of using Vector, for example, you can use java.util.ArrayList. Instead of Hashtable, use
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Leave a Reply