wood burning stoves 2.0*
The moose likes Servlets and the fly likes Example for load a servlet repeatedly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Example for load a servlet repeatedly" Watch "Example for load a servlet repeatedly" New topic
Author

Example for load a servlet repeatedly

Jeremy Flowers
Greenhorn

Joined: Aug 04, 2005
Posts: 11
I was reading this section on 'Servlet Reloading' of Jason Hunters Java Servlet Programming.
Then I went in search of an example.
I read in Core Java II Advanced Features Vol II 7th ed.

On P696 it mentions using classloaders to facilitate such things as hot deployment of servlets and EJBs.
It makes references to this broken link:
http://developer.java.sun.com/developer/TechTips/2000/tt1027.htm
I'm wondering if anyone knows what's become of this document?
(I couldn't see it on the Waybackmachine either.
Does anyone have a link that:
1) Shows a custom class loader to load servlets repeatedly?
2) A new link for the broken one?
Cheers.
karan khosla
Greenhorn

Joined: Apr 27, 2009
Posts: 25

Are you using ajax or jquery in your application or rather the page for which you want to reload the servlet everytime. If yes than it's quite possible to achieve without this classloading stuff.

Hope this Helps!
Regards,
Karan


Karan Check me out on http://pythonicway.blogspot.com/
Jeremy Flowers
Greenhorn

Joined: Aug 04, 2005
Posts: 11
karan khosla wrote:Are you using ajax or jquery in your application or rather the page for which you want to reload the servlet everytime. If yes than it's quite possible to achieve without this classloading stuff.

Hope this Helps!
Regards,
Karan

Hi Karan.
No this was something I saw in a Java interview question and was curious to know how to do this. It's something I've never come across before.
karan khosla
Greenhorn

Joined: Apr 27, 2009
Posts: 25

Well Sir you have to first clear me that are you using ajax or jquery in your application? If not than i guess it's a bit long path.

Either ways it will take some time for me to actually code an example for you.

Regards,
Karan
Jeremy Flowers
Greenhorn

Joined: Aug 04, 2005
Posts: 11
karan khosla wrote:Well Sir you have to first clear me that are you using ajax or jquery in your application? If not than i guess it's a bit long path.

No Ajax/JQuery. Plain old Java only (Servlets forum). :-)
karan khosla
Greenhorn

Joined: Apr 27, 2009
Posts: 25

No Problems. I will show you both ways but as i said i need some time to code a sample application when i am done with that i will post here. It's actually a good question i will be posting the same on my blog [http://pythonicway.blogspot.com/] only after it works for you.


Regards,
Karan
Jeremy Flowers
Greenhorn

Joined: Aug 04, 2005
Posts: 11
If you've got any links that you think would be worth sharing, that would be cool too. Thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42038
    
  64
What Jeremy is asking about has nothing to do with AJAX and/or jQuery. The "reloading" in question is not the repeated accessing of a web page by a client, but the reloading of a servlet class after its code has changed.

Those early Java Tech Tips have gone missing a while ago, and are unlikely to resurface; you can find an archived copy here. More recent ones from 2007 onwards can be found at http://java.sun.com/developer/TechTips/index.html.


Ping & DNS - my free Android networking tools app
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

I have no idea why client-side technologies like AJAX would have anything at all to do with hot deployment of servlets, which is entirely a server-side requirement. But perhaps Karan will enlighten us eventually.

In the meantime, I have to ask why you are so interested in this? That book was written back in the dark ages -- the page you linked to is dated March 2001, ten years ago -- which is why you can't find the other pages you were looking for. A lot of servlet containers these days have addressed that problem since that time and support hot-deployment via a configuration option. Or were you considering writing your own servlet container?
Jeremy Flowers
Greenhorn

Joined: Aug 04, 2005
Posts: 11
Paul Clapham wrote:I have no idea why client-side technologies like AJAX would have anything at all to do with hot deployment of servlets, which is entirely a server-side requirement. But perhaps Karan will enlighten us eventually.

In the meantime, I have to ask why you are so interested in this? That book was written back in the dark ages -- the page you linked to is dated March 2001, ten years ago -- which is why you can't find the other pages you were looking for. A lot of servlet containers these days have addressed that problem since that time and support hot-deployment via a configuration option. Or were you considering writing your own servlet container?


I figured the outdated article if it was still around somewhere would give me enough information to understand how you'd implement loading a servlet repeatedly using a classloader, which I guess is the real "nut I'm trying to crack"!
Cheers.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Jeremy Flowers wrote:I figured the outdated article if it was still around somewhere would give me enough information to understand how you'd implement loading a servlet repeatedly using a classloader, which I guess is the real "nut I'm trying to crack"!


Okay... but I'm still curious about why you are trying to crack that nut in the first place.
Jeremy Flowers
Greenhorn

Joined: Aug 04, 2005
Posts: 11
Paul Clapham wrote:
Jeremy Flowers wrote:I figured the outdated article if it was still around somewhere would give me enough information to understand how you'd implement loading a servlet repeatedly using a classloader, which I guess is the real "nut I'm trying to crack"!


Okay... but I'm still curious about why you are trying to crack that nut in the first place.


Curiousity. :-) Classloaders in general are a weak spot for me. A use case giving a reason why you'd loading a servlet repeatedly with a classloader would also help.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42038
    
  64
Jeremy Flowers wrote:Classloaders in general are a weak spot for me.

If I may strut my own stuff: Here's an article I wrote a while back that demonstrates a custom classloader in action. It's a desktop app, not a web app, but the source is included so it's easy to experiment with it.

A use case giving a reason why you'd loading a servlet repeatedly with a classloader would also help.

It used to be that starting and stopping a web app was a rather slow process (we're talking 10 years ago here), so to make the development process faster servlet containers would check the date/time on servlet class files, and automatically reload them if the date was newer than the last known date. These days, containers can be set to reload the entire web app which -given the speed of current machines- is generally a pretty fast process, so the possibility of reloading single servlets has gone away.
karan khosla
Greenhorn

Joined: Apr 27, 2009
Posts: 25

Hi, Paul/Ulf

Well via ajax or jquery and reloading a servlet is a easy bet in the sense that you can pass any random value to a servlet as request parameter which will force the container to relead the servlet for you for now i can tell only this thing. And yes maybe you both are correct that what Jeremy was asking is something different than what i thought than, i would say the classloader stuff is another way to go.

Regards,
Karan
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

HItting the servlet with a request does not "reload" the servlet. You are confusing reloading with returning a response,


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeremy Flowers
Greenhorn

Joined: Aug 04, 2005
Posts: 11
Bear Bibeault wrote:HItting the servlet with a request does not "reload" the servlet. You are confusing reloading with returning a response,

Was that meant for Karan? :-)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

Yes.
karan khosla
Greenhorn

Joined: Apr 27, 2009
Posts: 25

Hi Bear,

Sir, You're Correct that hitting a servlet with request won't reload a servlet but if the servlet takes request parameter and you change that parameter on every call via a ajax or jquery it will force the underlying container to reload the servlet for sure. Still i would say correct me if i am wrong. I did this thing in one of my projects and it worked for me at that time.

Regards,
Karan
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

This is still incorrect. A servlet gets loaded by the container and uses that single instance to serve all requests of that type. The container can decide to undeploy a servlet and then redeploy a servlet, but in practice this is unlikely to point that I've never seen single case of this in over 12 years.

Sending different request parameters will not cause the servlet to undeploy, it will not cause a new instance to be created.
If you can show otherwise then please post the code and steps to reproduce it here.

If the browser sends a request to the servlet then the browser may show new information on the client side, but this has no relation to the single servlet instance which exists on the server.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42038
    
  64
karan khosla wrote:Still i would say correct me if i am wrong.

You're wrong :-)

"reloading a servlet" has nothing at all to do with "reloading a page served by a servlet". Jeremy asked about the former, while Karan is talking about the latter.
karan khosla
Greenhorn

Joined: Apr 27, 2009
Posts: 25

If you guys think i am wrong than i accept that :-) Still in a learning stage. Maybe i am not able to completely understand the scenario or what i did is something different. :-)

Regards,
Karan
 
GeeCON Prague 2014
 
subject: Example for load a servlet repeatedly