0

This may be a somewhat...unorthodox question. I have multiple apps running in the same JVM, each in their own classloader. These apps need to communicate with eachother (only a little bit though), but I can't add shared code of my own to a classloader these apps share, so I need to do it with facilities provided by the standard Java runtime.

I thought along the lines of using System properties. However, it'd be hard to make thread-safe, though I suppose I could use synchronized on an interned long random String.

Any more options?


The communication I want goes as follows. This may affect the suitable options.

  • Each app, in sequence, puts its name in a shared queue.
  • Each app, at the same time, starts polling the queue to see whether its own name is at the head. If it is, it will perform a long running init task, then pull its name from the queue.
Bart van Heukelom
  • 43,244
  • 59
  • 186
  • 301

1 Answers1

1

Any structure that uses the standard system classloader types, with synchronization applied. Maps of strings and integers work fine.

This means you can also use any of the java.util.concurrent classes, which may have suitable queues for your problem.

krosenvold
  • 75,535
  • 32
  • 152
  • 208
  • The problem is I don't just need to use code that's available by default, but shared data as well. Some shared data I can think of are System properties and interned Strings. – Bart van Heukelom Sep 24 '13 at 12:52
  • I don't see how this would be a problem ? Just put the interned string in the map/queue ? It does, of course, get a bit ugly... – krosenvold Sep 24 '13 at 12:54
  • This won't work as the two apps have no way to access the same data structures as there is no central point of access (something like a singleton or so). – isnot2bad Sep 24 '13 at 12:54
  • "Just put the interned string in the map/queue" - That's the thing, which map/queue? Where do I put that? – Bart van Heukelom Sep 24 '13 at 12:55
  • @krosenvold, as long as your applications load the `String` class using the system class loader they can share all instances of `String`, not only interned strings. – Joni Sep 24 '13 at 12:57
  • @BartvanHeukelom It seems to me like you're trying to solve multiple problems: A) How to pass data between the JVM's and B) how to get the shared data into each JVM. If you don't have good control of the creation of all the classloaders, you could just put an object in a system property. – krosenvold Sep 25 '13 at 11:47