File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes singletons & servlets... Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "singletons & servlets..." Watch "singletons & servlets..." New topic
Author

singletons & servlets...

Dave Brown
Ranch Hand

Joined: Mar 08, 2005
Posts: 301
Hi all,

I have a question whether I'm approaching something with the correct philosophy..

In my web app I want to add a socket listener, so certain devices belonging to customers can connect via sockets rather than keep sending http requests as at present..

What I also want to do is allow them, when logged in to see that their device is in fact connected via a socket and let them do certain things..

My puzzle is the approach for the socket listener.. My plan was to have a SocketListener servlet which loads on startup and sits listening.. I suppose it doesnt have to specifical be a servlet but a plain old class, but I want to it to definately start when the webapp starts.. thats why I thought a servlet would be a suitable approach..
And as I said I need to be able access the class/servlet in a singleton fashion so I can check whats connected to it and other functions..

Has any thoughts they could share ?


Regards, Dave Brown
SCJP 6 - [url]http://www.dbws.net/[/url] - Check out Grails Forum
Colin Shine
Greenhorn

Joined: Aug 12, 2005
Posts: 26
You could use a class implementing the ServletContextListener interface. It can be a regular class. Configure it in web.xml as:

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35440
    
    9
A better approach would be to use a ServletContextListener (some info here under "Lifecycle events"). Using servlets loaded st startup for this kind of thing is kind of an abuse of servlets.


Android appsImageJ pluginsJava web charts
Dave Brown
Ranch Hand

Joined: Mar 08, 2005
Posts: 301
Thanks guys, thats exactly what I need.

Dave
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: singletons & servlets...
 
Similar Threads
UDP broadcast on multiple interfaces
Simple schedule
Singleton ( a Deeper Understanding )
best approach..
can a cellrenderer implement MouseListeners??