Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Interprocess synchronization  RSS feed

 
jeff wisgo
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating an application which uses a database as a persistent queue. I have one process writing to the queue (which happens to originate from a servlet), and one process reading from the queue. This seems to be the classic producer-consumer problem, except that I cannot use notify/wait because I am using different processes in different JVMs (at least that is my understanding - I am under the impression that a servlet executed by Jakarta-Tomcat and a processes executed via the command line run in different JVMs).

I know I can use RMI, CORBA, or Sockets to communicate, but I dont want the queue-reader to be doing any sort of polling, I want it to block until something is added to the db (without constantly reading the db). I cant think of a really clean way to implement this, is there any 'natural' way to this in Java?

Thanks alot for the help.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You named a few inter-process protocols. I'd go with one of those that makes you comfortable. Probably sockets for me. The process that writes the database can publish "I just updated the database" to all interested listeners. I'd make interested listeners do some kind of subscribe or addListener so the db updater doesn't have to know about them at compile time. JMS has a good pub-sub paradigm if you happen to have a JMS provider under the covers somewhere.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An RMI-callable object or a daemon thread waiting for socket data would do the job (both are one and the same thing anyway). But why on earth don't you use JMS? It sounds like it's exactly the abstraction you need.

- Peter
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!