I have a need to create a new entry point for a jetty server. This server will create an instance of the jetty container and then in a second thread create a datacollector instance.
My qeustion is how do i set this up so that the servlets running in the container can see the datacollector class?
The purpose behind this is to have a webpage control the state for the datacollector instance. All the datacollector does is goes to a data source (database) and reads the data in a table and loads a file with the contents of the table. I have this setup so that the datacollector will read the table once every 5 minutes. I want to be able to control, from the webpage, all of the attributes of the datacollector instance (example: start, stop, debug mode, ect).
Start the DataCollector when the webapp is deployed (using a ServletContextListener), stop it when the webapp is destroyed (using the same listener), and make the DataCollector a singleton or store it in a servlet context attribute to be able to get it from any component of the webapp.
That said, are you sure you couldn’t simply read from the database table every time you need to send the data to the response? Databases are very fast, especially on small tables.