O'Reilly logo

Sams Teach Yourself J2EE™ in 21 Days by Peter Roxburgh, Andy Longshaw, Debbie Law, Dan Haywood, Martin Bond

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Servlet Threads

In the AuditFilter example, several lines of code were encased in a synchronize block. This was done to ensure that the counter would be correctly incremented if more than one access is made to the page at the same time. Without the synchronize block, it is possible for two (or possibly more) servlet threads to obtain the counter value before it has been incremented, thereby losing one of the increments. In this case, failing to count one page hit is not a significant problem. There are other situations where it might be.

Shared resources, such as files and databases, can also present concurrency issues when accessed by more than one servlet at a time. To avoid concurrency issues, a servlet can implement the single-thread model. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required