I am newbie to web services.i am trying to understand jersey implementation of restful. i have some doubt that i googled it but could not get satisfactory answer
As we know following life cycle phase of servlet :
Loading and instantiation: At the time of instantiation servlet container call init(ServletConfig) this method is called only once in whole life cycle of servlet. Key point is that container will create object only once in whole life cycle of servlet.
Service :Once Loading and instantiation is done each request coming to this servlet handle by service method.Now for next request container will not create object of servlet again it create separate thread to handle newly coming request.This is one of the major cause of good performance of servlet over CGI application because (In CGI every time there's client request, HTTP server creates new instance of process to serve this request. This is performance killer).
Destroy : Container calls destroy() method to indicate to a servlet that the servlet is being taken out of service. This method is only called once all threads within the servlet's service method have exited or after a timeout period has passed.
Am i right ?
Now comming to second part what i got when we create resource in jersey for each comming request container create seperate instance of resource class as we can see each time constructor is called.
@Path("myresource")
public class MyResource {
public MyResource(){
System.out.prinln("hi");
}
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getIt() {
return "Got it!";
}
}
My question is how jersey process is different from CGI ? if not why people compromise with performance?