{{theTime}}

Search This Blog

Total Pageviews

Showing posts with label servlets. Show all posts
Showing posts with label servlets. Show all posts

What is a Servlet


A servlet is a server-side program written in the Java programming language that interacts with clients and is usually tied to a HyperText Transfer Protocol (HTTP) server. One common use for a servlet is to extend a web server by providing dynamic web content.
Servlets have an advantage over other technologies in that they are compiled, have threading capability built in, and provide a secure programming environment. Even web sites that previously did not provide servlet support, can do so now by using programs such as JRun or the Java module for the Apache web server.



http://java.sun.com/developer/onlineTraining/Programming/JDCBook/aucserv.html

Servlets multi threaded Service method


Threading
A servlet must be able to handle multiple concurrent requests. Any number of end users at any given time could invoke the servlet, and while the init method is always run single-threaded, the servicemethod is multi-threaded to handle multiple requests.
This means any static or public fields accessed by the service method should be restricted to simple thread access. The example below uses the synchronized keyword to restrict access to a counter so it can only be updated by one thread at a time:
  int counter
  Boolean lock = new Boolean(true);

  synchronized(lock){
    counter++;
  }

AI Predictive Bot - Scenario Model

  💡 How to Read the Costco Scenario Model This simulator bridges the gap between how a company operates (its business performance) and how...