CHAPTER 10 INTRODUCTION TO (Web design company) FILTERING 429 while

CHAPTER 10 INTRODUCTION TO FILTERING 429 while others may save you significant debugging time during the development cycle. This section presents an encapsulation of six such guidelines. You ll see several more in the next chapter when you explore the design and coding of more complex filters. Make Code Thread-Safe Making code thread-safe cannot be stressed enough. Remember that there is typically only one instance of a filter per Java VM (unless the same filter is declared multiple times with different names or initial parameters). This makes it inevitable that the doFilter() method will be entered by many threads simultaneously, so your filter code must be thread-safe. This means the following: Local variables in doFilter() may be used freely (except for complex objects that may hold references to instance variables, in which case the next bullet applies). Instance variables in the filter class scope should be read-only, or the scope s access must be synchronized. Beware of calling methods that may modify instance variables indirectly or outside of synchronization. Figure 10-12 provides a spatial representation of this approach. Figure 10-12. One of the first steps to writing thread-safe filters is to make instance variables read-only, or access protected. Local variables are generally thread-safe and can be used to store request-specific information. Handle State Carefully State information can be readily maintained via local variables in doFilter(). The prerequest and postresponse processing window within the doFilter() method has full access to this state information. To pass state information between filters on the same chain, you can associate attributes with the ServletContext, returned by the FilterConfig.getServletContext() method. The reason why ServletContext attributes rather than request attributes can be used will be clear when you examine request and response wrapping in the next chapter.
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Leave a Reply