Jigar Damani wrote:But what is the actual (logical) reason behind such kind of feature?
2. Synchronization of constructors not allowed in Java - why?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Jigar Damani wrote:Make constructor synchronized.
Construct is special kind of method so why we can synchronized method but not Constructor.
Constructor is not synchronized so how following situation would be handled by container?
Assume simultaneously 100 requests come for same Servlet (assume requests come at same time from all client to server).
On first request, container will create object of class and then thread. So if 100 request comes simultaneosly, How it will synchronized object creation?
So how container handle this situation?
Jigar Damani wrote:Construct is special kind of method so why we can synchronized method but not Constructor.
Constructor is not synchronized so how following situation would be handled by container?
Assume simultaneously 100 requests come for same Servlet (assume requests come at same time from all client to server).
On first request, container will create object of class and then thread. So if 100 request comes simultaneosly, How it will synchronized object creation?
So how container handle this situation?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Jigar Damani wrote:Because for concurrent request Container try to load memory so it should load Servlet in memory 100 times.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Jigar Damani wrote:
Still I have one doubt.
Servlet would be loaded in memory only once for first request. For subsequent request it will not be loaded in memory.
If 100 concurrent request comes to server at the same time (assume it), so how this situation Container tackle?
Because for concurrent request Container try to load memory so it should load Servlet in memory 100 times.
Winston Gutkowski wrote:
Jigar Damani wrote:Construct is special kind of method so why we can synchronized method but not Constructor.
I ask again: What would it be synchronized on?
A synchronized instance method is synchronized on its instance, but in the case of a constructor there is no instance, because you're in the process of creating it.
Winston Gutkowski wrote:A synchronized static method is synchronized on its class. I suppose this would be possible, but do you really want to be locking an entire class simply because you want to create an instance? Furthermore, since all constructors eventually call Object's, this would presumably involve locking out Object.class every time ANY object is created. Ooof.
get schwifty. tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|