Could/should I use EJB in this scenario?
I have a servlet that implements the answer to this solution (sweets packet answer):
When I apply the above solution to my servlet I get an IllegalMonitorStateExcepti
on, although I have an JSE version which works.
I am managing the threads myself in the servlet without the use of EJB.
To use the above metaphor, the sweets packet (persistent object) is instantiated, then children (client side) would grab sweets over http (entering on servlet thread_1) and the parent would replenish sweets from the database (server side working in daemon thread_2).
In real life a screen extending the Screen class is instantiated in a servlet (running in thread_1). The client might make a request like "purchase" to the server. The purchase method of the screen object is invoked on a second thread (thread_2). That purchase method might require client input, so it could pause itself and resume the servlet thread to prompt for client input. When the client input arrives, the servlet thread would pause, waiting for further instructions from the purchase method etc.
Can I run a statefull session bean (SFSB) in a new thread and pause its execution while an http request completes as below?
An http conversation might look like this:
[http post request] client clicks : "purchase"
[thread_1] servlet invokes purchase method in thread_2 and pauses itself]
[thread_2] purchase method starts, hits database etc. needs client input, pauses itself, resumes thread1
[http post response] servlet message "how many"
[http post request] client enters : "5"
[http post response] servlet message "here is 5 for you"
[thread_1] servlet resumes thread_2 and thread_1 dies
[thread_2] completes and dies