1 / 9

Servlet Life cycle

Servlet Life cycle. Bill Chu. Java. JAVA as an object oriented language Learned from experiences of other OO languages More completely defined library JAVA as a platform JAVA virtual machine (JVM) More completely defined run time environment “develop once, run everywhere” JVM

twyla
Download Presentation

Servlet Life cycle

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Servlet Life cycle Bill Chu

  2. Java • JAVA as an object oriented language • Learned from experiences of other OO languages • More completely defined library • JAVA as a platform • JAVA virtual machine (JVM) • More completely defined run time environment • “develop once, run everywhere” • JVM • Class loader • Byte code checker • Security Manager © Bei-Tseng Chu Aug 2000

  3. Process and threads • Process: A program in execution. It consists of the executable program, the program’s run time status • Data • Stack • Program counter • Registers • Thread: a program in execution, but is part of a process. It consists of its own: • Stack • Program counter • Registers • Share data with other threads of the process © Bei-Tseng Chu Aug 2000

  4. Process Takes more time to create More secure More fault tolerant Thread Takes less time to create Offers multiple threads of execution Share information with other threads Less secure More vulnerable to crashes Contrast of process vs. thread © Bei-Tseng Chu Aug 2000

  5. JVM and servlets • UNC Charlotte server configuration • All servelets share the same JVM • Servelets are loaded when they are first called and stay loaded • Update to servelets needs to be reloaded • For production servers, servelets are often pre-loaded • Servelets can have dedicated JVM’s to help with reliability © Bei-Tseng Chu Aug 2000

  6. Servelet life cycle • Each servelet instance is loaded once • Each execution happens in a separate thread • Method init() is only called once during initialization of the servelet • Method service() is invoked every time a request comes it. It spawns off threads to perform doGet or doPost based on the method invoked • Method service should not be redefined • Method doGet and doPost typically need to do perform the same actions (p.36) © Bei-Tseng Chu Aug 2000

  7. Data synchronization over multiple threads • Consider the example of a shopping cart application implemented using a servelet. • Suppose one browser wants to bump the items ordered from 1 to 3 • Suppose another browser wants to change the items ordered from 1 to 0 • Suppose the submit buttons are pressed at exactly the same time • We cannot predict what would be the final number of items ordered © Bei-Tseng Chu Aug 2000

  8. Single thread model servelet • Single thread servelet is possible • It can avoid many of the data synchronization issues • However, it severely limits performance © Bei-Tseng Chu Aug 2000

  9. destroy method • Before the servelet is removed, the destroy method is invoked • It can be used to “clean up” environments such as database connections. © Bei-Tseng Chu Aug 2000

More Related