0

Grasping at straws for search parameters and terminology.

The key attribute to the JVM is the V for virtual (at least within the context of this question). How do you span a JVM across a cluster of machines with load balancing so that the JVM itself is distributed?

sorta kinda like this:

distributed JVM

https://www.cacheonix.org/articles/Distributed-Java-application-on-multiple-JVMs.gif

so that the application only sees a single JVM?

1
  • 1
    If this is a webapp, you should look at the clustering features of Java servers such as Glassfish or Websphere. Still using the mechanisms B Layer explaines in his answer,
    – MAQ
    Aug 20, 2017 at 16:07

1 Answer 1

2

Elaborating on my comment and assuming that you aren't thinking of something very esoteric...

Perhaps you're looking at that diagram and interpreting it as if the users are using an application that can talk to any JVM on the backend at any time during a session because of some kind of coordination between the JVMs. That's not how it typically works...at least not in widely used architectures.

The diagram is almost certainly depicting a classic distributed environment with independent JVMs. If the client (the user application) requires that state be maintained between requests (a session) there are several options but they all still involve JVMs with no knowledge of other JVMs.

The most straightforward and common way to accomplish this is to use a load balancer that supports so-called sticky sessions. Briefly, that means that once the client has established identity then the load balancer will always route the client's requests to the same JVM for the duration of the session (e.g. until the user logs out).

What do I mean by identity? Usually that means the user has logged in and successfully been authenticated after which a unique ID will be chosen and associated with all of the user's subsequent requests. In the case of web apps (such as those using a RESTful API) this ID is often passed around in an HTTP header. Using a header like this makes it easy for most load balancers to extract the ID.

Alternatively, you can forgo sticky sessions and store session state in a DB, for instance, and require a JVM to lookup that state using the session ID each time a request is received. This adds some complexity and overhead but is not unheard of. The JVMs are still independent in this model, though.

(You could also have the client application pass session state in it's entirety in every request it makes but there are security issues with this, among other problems.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .