Concurrent Session-Independent Java Web App?
Question
Is it possible to deploy an application to a GlassFish app server that would behave more like a daemon than a web app? I'd like to set up some sort of daemon app that would relay requests to an API that only allows for one connection at a time.
This way I could have multiple servlet instances that could simply submit API requests through the daemon and avoid ever needing more than one connection to the API.
I'm fairly new to Java-based web apps, so I'm not entirely certain what to search for, or if this kind of functionality is available in, say, the Java-EE development kit. Any help appreciated!
Updates/Ideas:
- Lifecycle Module: What about building the daemon as a lifecycle module? From what I gather, I could effectively manage its behavior based on the app server's status, which could actually be beneficial in my case: http://docs.sun.com/app/docs/doc/819-3672/beamc?l=en&a=view
Solution
GlassFish v3 supports EJB 3.1 Singleton Beans:
A Singleton Bean could be used to implement the requirement "relay requests to an API that only allows for one connection at a time".
By default, all Singleton methods are made thread-safe and transactional. This means that all multithreaded access to the bean is serialized (...)
OTHER TIPS
Sounds like you want a servlet that feeds a message queue. Then you can have some code that pulls entries off the queue and processes them. Look up Message-Driven Beans.