Servlet question: How do i interrupt & resume execution?

T

Tony

Ive been trying to figure this out and I just can't. Any help would be most
appreciated.

My problem in a nutshell is:

I'm trying to write a web (servlet) based application. The business logic
involves a recursive method which may (part way through the recursion) need
to pause, prompt the user for a value, and then continue. I don't believe
that multi-threading is required, as the original routine will be paused
until the user has provided a value. However, I just can't seem to come up
with the right basic architecture.

So basically, I need to have control returned to the recursive function once
the user has responded to a prompt.

Any thoughts/suggestions on how this would be done would be greatly
appreciated.

Thank you.

Tony
 
A

Andy Fish

Tony said:
Ive been trying to figure this out and I just can't. Any help would be most
appreciated.

My problem in a nutshell is:

I'm trying to write a web (servlet) based application. The business logic
involves a recursive method which may (part way through the recursion) need
to pause, prompt the user for a value, and then continue. I don't believe
that multi-threading is required, as the original routine will be paused
until the user has provided a value. However, I just can't seem to come up
with the right basic architecture.

So basically, I need to have control returned to the recursive function once
the user has responded to a prompt.

Any thoughts/suggestions on how this would be done would be greatly
appreciated.

since you want to go back to the user, you are talking about having two (or
more) separate servlet invocations: one which initiates the long-running
process and another which supplies a parameter mid-stream. I can think of 2
ways to solve this:

1. if at all possible, try to have the recursive algorithm work in such a
way that it can save it's state into some kind of object and return it. then
you can put that state object in the session and later use it to resume the
recursive algorithm from the second servlet invocation.

2. use a separate thread to perform the recursive algorithm and have the
servlet(s) communicate with that thread through a shared object. This is too
complicated to give a simple code example for, but you will need to read up
about java thread synchronization. in this scenario you will need to put the
thread object (or something that points to it) in the session so that you
can find it in the second servlet invocation. you will also need to include
clean-up code so that in the event the user does not reply the thread is
terminated.

I would strongly advise the first option. rather than thinking of it as a
single recursive algorithm, try and think of it as a number of steps with
some possible user interaction between each step, then think about what
parameters must be passed from the first step into the second. Possibly the
steps are the same actual code but with different state.

failing all that, question whether it needs to be web based. if you can make
it into a GUI app, you can stop the algorithm and ask for more info at any
point and then resume, which is just not possible with a servlet.

Andy
 
H

Hal Rosser

a JOptionPane.showInputDialog box will wait for user input - then the
program picks up from there after the user enters the data
 
Joined
Aug 10, 2010
Messages
4
Reaction score
0
Tony said:
Andy, Hal,

Thanks very much for your help with this.

Tony

Hi everybody,

You can see same topic at the side bar of this site. You can find out some thing same your questions or use search box or this site.

Best rgs
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top