Define MultiTasking in Java

MultiTasking :

There are two types of executing the statements in MultiTasking.

Executing several task at a time by the microprocessor is called MultiTasking.

In MultiTasking the processor time is utilized in an optimum way

The 2 type of MultiTasking are as follows.

(i) Process Based MultiTasking :

In this several programs are executed by the Microprocessor using RoundRobin Method.

(ii) Thread Based MultiTasking :

Executing different parts (methods ) of the same program at a time using thread is called Thread Based MultiTasking.

What is Port Number

The unique ID number alloted to a socket is called Port Number

Servlet Summary

–> A servlet is a Java class that runs on a server, and a servlet for a web application extends the HttpServlet class.

–> When you write servlets , you override the doGet and doPost methods to provide the processing that’s required. These methods receive the request object and the  response object that are passed to them by the server.

–> After you use the setContentType method of the response object to set the content type of the response that’s returned to the browser, you use the getWriter method  to create a PrintWriter object. Then, you can use the println and print methods of  that object to send HTML back to the browser.

–> The class files for servlets must be stored in the WEB-INF\classes directory of an  application or in a subdirectory that corresponds to a package name.

–> To request a servlet from a URL, you include the word “servlet” after the document root directory in the path. This is followed by the package name, a dot, and the servlet name.

–> You can override the init method of a servlet to initialize its instance variables. These variables are then available to all of the threads that are spawned for the one instance of the servlet.

–> When you code a thread-safe servlet, you prevent two or more users from accessing  the same block of code at the same time.

–> To print debugging data to the server console, you can use the println method of  the System.out or System.err object. An alternative is to use the log methods of the  HttpServlet class to write debugging data to a log file.

Explain the Instance Variables in Servlets

instance variable

–> An instance variable of a servlet belongs to the one instance of the servlet and is shared by any threads that request the servlet.

–> You can initialize an instance variable in the init method.

–> If you don’t want two or more threads to modify an instance variable at the same time, you must synchronize the access to the instance variables.

–> To synchronize access to a block of code, you can use the synchronized keyword and the this keyword.

How to limit the use of code to a single thread at  three different levels. First, you can synchronize a block of code by using the synchronized and this keywords. Second, you can synchronize an entire method. Third, you can use the SingleThreadModel interface to limit the use of  an entire servlet to a single thread. That way, you don’t have to synchronize any  of the code within the servlet.

you must remember that one thread has to  wait while another thread is using a synchronized block of code, a synchronized method, or a single-thread servlet.