1

I have an object that processes text in a stateless way. It basically takes some input and returns the result. However, creating the object is expensive, as it needs to load a lot of data into memory. I would like to build a web service around it using Jetty, so that I can parse text from external sources. Jetty should keep a pool of such objects in memory and use them to process the HTTP requests (making sure that a single object is being used by only one HTTP thread at a time). How can I configure the server to do it?

skaffman
  • 398,947
  • 96
  • 818
  • 769
pako
  • 1,908
  • 4
  • 24
  • 40

1 Answers1

3

Jetty by itself is not going to help a lot on this, but you can easily plug the pool component of Apache Commons to achieve what you want.

Then. from your web service, you can just reference this object pool to get your processing object.

Nicolas Modrzyk
  • 13,961
  • 2
  • 36
  • 40
  • How does it work? I mean the interface seems pretty simple, but how do I integrate the object pool into my web application? Does it run as a separate process, or as a separate thread managed by Jetty? – pako Feb 06 '12 at 11:40
  • It depends on the framework for your webapp. In a simple way, you can make this object static and make it thread safe. In a more subtle way you could use JNDI. (http://humblecode.blogspot.com/2009/05/gwt-16-using-jndi-datasource.html) – Nicolas Modrzyk Feb 06 '12 at 12:11