views:

49

answers:

1

I have an application solution which is made up of a web app written in Python (using Django framework) and a Java application which runs on the server.

The web application receives data and stores it into a database queue. The Java application is then to process the received data and also store the results in a database.

My question is how can the Java application be notified that there is new data in the database? Right now, it seems like I will have to regularly poll the database for new data. Is there any way around this?

PS. I have considered running the web app using Jython and using the Observer pattern but my host does not support Servlets.

+1  A: 

Unless the database specifically supports it, polling is the only option I know of.

However, if your concern is load on the Java server, you could have another server that does nothing but polls for changes and then notifies your Java server when changes have occurred. I don't know if that is any better than doing a simple polling from the Java server (not knowing your specific problem space and hardware constraints).

Hope that helps.


Edit: after reading your statement again, it seems like you are already doing a messaging like framework (with the queue in the java application) so the database change could simply be another message that goes into the queue. If it needs priority, you could give the messages priority marks so that they get processed when they need to be processed.

aperkins
Thanks for your response. Yes, it is a messaging framework, but I do not have priorities for now. The users just should not wait too long to get a response. If I poll too often when load is light, I feel like I'm wasting resources. If I poll less often when load is high, users may start feeling the latency. I guess I'll have to find a good balance.
codinguser
Polling often is probably better, if you're worried about performance try to optimize your database. I think the queue should be an empty table when there's no message (don't keep old records there).
Damien
@Damien thanks for the tip.
codinguser
@Damien: Exactly. I was trying to get to that point, and failed miserably in my description. Thanks for adding in the tip :)
aperkins