Re: is using applet-servlet communication to implement realtime features possible?
tony wrote:
tony wrote:
I'm on a stock(i.e. securities) project.
I have an applet showing the current prices of the stocks
and as required, the applet communicates with servlet and
servlet accesses database. Whenever prices changed, messages
should be sent to the applet.I use triggers to do the
database->servlet part, but how can I do the servlet->applet part?
As far as I know, servlet responses if and only if a request
comes to it. So is that possible?
Thank you!
Is my question so ambiguous that nobody wants to answer it?
One way is for an applet to make a request to a servlet which blocks waiting for
a response. So you could possibly get it to work using threads. A background
thread in the applet could make a request to the servlet, and this only returns
when there is a price change to report. When the request returns to the applet
this new data can be made available by some mechanism to other threads in the
applet. Those other threads can process the data whilst the background thread
makes another blocking request. You'd have to handle timeout on the blocked
request, as well as network outages and the like. And properly synchronize the
data shared between the threads in the applet.
You would also need to take account of what happens to price updates which occur
whilst no request is currently blocked, i.e. during the period between one
request returning with an update and the applet background thread making
another request. You wouldn't want updates during this time interval to fall
through the cracks so the servlet would need to cache updates somehow.
It won't be trivial.
I do something similar to this in a applet/servlet setup which displays realtime
data from a radar. However, if the comms. in my setup breaks no-one loses any
money...
--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555