I have two applications. One is a Java thick client Swing GUI for controlling some parameters which are stored in the DB. The other is a Java EE server side application which sends XML streams clients based on the parameters set by the GUI.
I would like the server side app to update its state as soon as the Swing 开发者_运维知识库GUI persists changes to the DB. What would be the best way of achieving this?
If the thick client is updating your database directly, then you have two options:
- Use database specific event notification. Capabilities and techniques vary greatly depending on database.
- Have the server-side application poll the database looking for changes.
Assuming your thick client updates the database through a server-side application then you have multiple options depending on actual design and implementation:
You could implement an observable pattern in your domain objects so that your server application can be notified anytime important domain objects are changed.
If using Hibernate, you could use Hibernate interceptors and events.
You could use a caching solution, such as Ehcache. (If you need transactional semantics, then perhaps JBoss Cache.)
You could use shared memory solutions such as Terracotta or Hazelcast.
What about making the Swing GUI app talk to server side app which talk to the db:
SwingGui -> ServerSideApp -> DB
Clients <-> ServerSideApp <-> DB
精彩评论