I have created a javaee application that among other things must perform sentiment analysis using naive bayes,. In order for the sentiment algorithm to work, we have to first train it,so I would like to create an object that would handle the trainning whenever the server is started to avoid training over and over again. I thought of using a singleton ejb to do this but I don't know if this is the correct way to go, also a friend suggested the use of managed beans. What are the pros and cons of those approaches for my problem? Am I looking in the correct direction or I am just barking in the wrong tree?
-
maybe have a look at http://stackoverflow.com/questions/9651132/jsf-singleton-vs-application-scoped-managed-bean-differences – djmj Apr 19 '12 at 22:37
1 Answers
MBeans are great for modifying the state of your application at runtime. If you want to alter the training of the algorithm at runtime and use MBeans, it could make sense to use them to initialize when you start up as well.
Also, I'd recommend in the design of the class containing your algorithm that you externalize the coefficients that you are calculating during training. You can then persist those coefficients and not have to re-run the training. On start your app would load the coefficients from persistence.
Combining loadable coefficients with MBeans, you could use the latter to retrieve or reload the set of coefficients at runtime. You would want to ensure reloading them is atomic. This would enable you to arbitrarily tune your analysis on the fly.

- 71
- 2