Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Database listeners  RSS feed

 
Michael Moser
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an app that is essentially a monitor of system status. The status is stored in a database table and can be updated by several different apps. My web app needs to display this status information and automatically update itself should any status change. I am interested in opinions as to how to do this in a J2EE implementation.

Thanks!
 
Warren Dew
blacksmith
Ranch Hand
Posts: 1332
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If what you want is for the web page to automatically update, I'm afraid you're going to have to make it poll the server periodically for updates, perhaps using JavaScript.
 
Michael Moser
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was coming to that same conclusion which was why I posted. How about applets? Can they maintain a listener?
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you only looking for the display to update, or must other things happen when changes occur too?

Kyle
 
Michael Moser
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Essentially just update the display. This would mean a reread of the table but that is about all that would need to occur I think
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also use JSP to do that and use META tag in that it will automatically refreshes the page.
<META http-equiv="refresh" content="2; URL=/samepage.jsp">
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree. Just use a meta tag (as above) to periodically force the browser to reload the page.

Kyle
 
damien malone
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
an applet would be better in that you could implement a push mecanism where you dont have to constantly poll the server, cutting down on network traffic and server load.

If you are going to get the page to refresh, I recomment you play around with the caching, so at least it should only download the page headers every minute, and the whole page only when the status chnges. To do this, keep a variable in memory that contains the time. When ever the status is changed, update this varialbe with the new time. Every time you request the page you want, set teh last-modified tag to the variable from memory. Also set the cache tags so that the page will be cached by the browser. That way the browser will get the latest of the page, get the headers every so often (you would probably set the refresh for something like 30 or 60 seconds) but as long as the status stays the same (and your variable with the last modified time of the status) the browser will get the HTML for the page from its cache, and not download it again from the server.

Damien
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I strongly disagree -- push mechanisms are quite difficult to get right, and many firewalls will not allow a server to initiate an outgoing connection -- not to mention the fact that the only way to allow an initiated connection from an applet is to sign the applet -- defeating the purpose of the applet sandbox.

Kyle
 
Michael Moser
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Kyle that the push is tricky and might complicate maintenance down the road. I was hoping to get some ideas from everyone on how to do this other than with a page refresh but I am not seeing much. The only reason I dislike the page refresh is that in order to reduce the network traffic, I need to make the auto-refresh at least a minute, if not more. But this delay makes it less realtime monitor than a near-realtime monitor. Perhaps someone knows of some COTS that has solved this problem?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!