1

I want to build realtime application using java. The web application always request data to server every 10 seconds, and display the fresh data on the web page.

do you have idea how to solve case like this ?

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
Adi Sembiring
  • 5,408
  • 12
  • 56
  • 70
  • 1
    the problem is, what makes ur application special than a normal ajax site ? – Dapeng Oct 03 '10 at 15:10
  • 1
    Are we talking about Java and Real-time? Together? Really? Maybe the term *asynchronous* would better fit :-) – Breaking not so bad Oct 03 '10 at 15:14
  • there are other application that always update currency information to data storage (csv file or xls file). I want to build application that read this file and displayed the updated data every 10 seconds. I need your suggestion, can the ajax query solve this case ? – Adi Sembiring Oct 03 '10 at 15:27
  • Hard real time is expensive. Can you do with "somewhat like" 10 seconds? – Thorbjørn Ravn Andersen Oct 03 '10 at 16:09
  • @Thorbjørn I dont know exactly, This is the first time for me having case like this. I ask this question here, in order to get best practice and better solution – Adi Sembiring Oct 03 '10 at 16:32
  • Have a look at http://stackoverflow.com/questions/3845597/what-constitutes-a-real-time-system regarding the term 'real-time'. – andersoj Oct 03 '10 at 18:34
  • @adisem, I believe that you may be misunderstanding the meaning of "real time", and hence we misunderstand what you actually want. Would "automatically update every 10 seconds" be better? – Thorbjørn Ravn Andersen Oct 04 '10 at 06:06

3 Answers3

4

Ajax will make your JavaScript code poll your site server to get the last value of the currency, say every 10 seconds. Meaning if 100 persons are connected, you'll get on average 100 accesses in 10 seconds.

Unless you use a Flash object or a Java Applet to establish a TCP-IP connection with your server (that can push the new value when it is available), Ajax is a better/easier option for you. The TCP alternative provides faster results (clients see the new value more in real time than with Ajax polling), and, usually, more efficient in terms of performance (Only push when a new value is available).

If you implement an Ajax polling system, you'll have to add server side an abuse detector: many people understand well JavaScript and some of them may change the polling frequency to have newer values faster... (like every second). Depends on the audience, the number of people accessing your site etc...
That detector would ensure that a given client does not exceed the polling frequency (e.g. more than once every 12 seconds, if the frequency is 10, with an error margin)

Breaking not so bad
  • 26,037
  • 5
  • 67
  • 96
  • you mean: if the user view expect 10 seconds to get updated data, It will be better if I set the request interview every 8 seconds ? – Adi Sembiring Oct 03 '10 at 16:08
  • Yes, either you poll every 8 seconds and check server side that the user is not exceeding 1 every 10 seconds (or you poll 10, and check for 12 seconds for instance...). A matter of taste. The idea is prevent a *refresh* order cancellation because of some network lag between the browser (client) and your server (I changed my sentence above since it was ambiguous and wrong). – Breaking not so bad Oct 03 '10 at 16:17
3

Use ajax to query the server every 10 seconds. You can easily achieve this by using jquery in the frontend.

Your backend don't need anything special but a good idea is use web service which will return an XML or JSON that will be parsed by the front end jquery to update the display.

mezzie
  • 1,196
  • 7
  • 12
0

If you are looking for a java framework then playframework or webfirmframework can be used. Spring + Angularjs is another way to do. Thay all are providing websocket communication which can be useful for realtime update. Handling everything with an ajar or our own implementation will take a bit time to become stable, because to handle hearbeat, intime opening & closing, reconnecting socket etc.. might be a bit difficult. If you google you can get a lot of tutorials for them.

RRadley
  • 313
  • 3
  • 7