Ok, yeah that makes sense. What you want to do then is ensure that your
business objects are only processing one thread at once. I'm guessing that
you could do this in a similar way that ejb containers serialize access to an
ejb.
(THinking aloud here): Lets see, you currently have an object, called say
BusinessBean that has a method called business(Object parameters), or
something similar?
rename business to doBusiness.
create a member of the BusinessBean for a lock and a flag to indicate if
we're active or not:
// the lock to serializing access
private Object LOCK = new Object();
// are we currently active
private boolean active = false;
replace the business method with something like this:
ReturnType business(Object parameters)
{
// is it ok to execute
boolean ok = false;
// while its not ok - look to see when it becomes ok
while (!ok)
{
// ensure we're the only one looking
synchronized(LOCK)
{
// if no one else is executing - lets go
if (!active)
{
ok = true;
// set the active flags so other
// threads will now wait
active = true;
}
}
// if its not ok to execute, wait
if (!ok) wait();
}
// execute the method and hold the return
ReturnType r = doBusiness(parameters);
// now reset the active flag and notify any waiting threads
synchronized(LOCK)
{
active = false;
notify();
}
// the final return
return r;
}
as I said.,.. thinking aloud (or via email)... but I think something like
that you would ensure that only one thread is executing on the doBusiness at
one time... although if you have a problem with the same command being
executed twice then you have to do other things too (o:
If I've missed something here, I'd love someone to point it out - I'm hoping
to get something out of this too (o:
cheesr
dim
On Wed, 20 Jun 2001 08:59, Russ Freeman wrote:
> Kind of :) In fact your solution isn't far away.....
>
> I am currently supporting multiple threads of activity within the same
> browser window and hence session.
>
> Let's say we have a big table on a page with two columns, where each column
> is like a "view". Each column view is displaying a different aspect of some
> business data and each column/pane has its own set of links too.
>
> If the user clicks a link in the left pane, the URI is sent with ID 1
> encoded in the URI and if they click a link in the right pane, the URI is
> sent with ID 2 encoded in it. (The ID is a lookup into a Map of business
> objects). This is similar to what you were saying I think.
>
> However this works OK until the user accidentally double clicks one of the
> links and the same business object gets two requests, where the first isn't
> finished before it recieves the second. So far I have ensured that each
> business object is thread safe and I have yet to detmine if this will work
> or whether I have just covered up another problem!
>
> Does this help?
>
> Cheers,
> Russ
>
> ----- Original Message -----
> From: "Dmitri Colebatch" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>; "Russ Freeman" <[EMAIL PROTECTED]>
> Sent: Tuesday, June 19, 2001 11:24 PM
> Subject: Re: multithreaded beans, struts, doing it right...
>
> > By multiple threads of activity do you mean the user has multiple windows
> > open? If so, perhaps in the user's session you could have a Map of
>
> business
>
> > logic beans instead of just one. And somehow have the client identify
>
> which
>
> > thread of activity the currenty action is part of, from there get the
> > apprpriate bean and you're back in single-threaded mode (o: Then again,
>
> if
>
> > this isn't what you mean, then thats probably no use!
> >
> > is that what you mean?
> >
> > cheesr
> > dim
> >
> > On Wed, 20 Jun 2001 08:08, Russ Freeman wrote:
> > > Hi folks, I have a question about building robust beans.
> > >
> > > Context:
> > > Building a Model-2 application with tomcat that uses a home-grown MVC
> > > framework (probably going to replaced with struts).
> > >
> > > My concern is over the design of my business logic beans, which are
> > > stateful controllers. Each of my user sessions can have one or more of
> > > these beans and each represents a separate thread of activity for the
>
> user.
>
> > > This is working OK except for the threading issue in that multiple
>
> requests
>
> > > (accidentally) sent the to same controller cause obvious problem. I
> > > have since added a level of synchronization and am hoping this will
> > > deal with most problems. Something I certainly don't want to do is to
> > > move away
>
> from
>
> > > stateful controllers (to avoid the threading problem) because I believe
> > > this is the right approach.
> > >
> > > Also from reading the struts docs carefully it appears that this is
>
> still
>
> > > something that must be considered with struts, i.e. once the Action
>
> object
>
> > > has passed on control to a bean, the bean has the concurrecy problem to
> > > deal with.
> > >
> > > So,
> > > I would be interested in people's opinion on their approach to managing
> > > concurrency in controller/business logic beans.
> > >
> > > Thanks in advance,
> > > Russ