Reputation: 173
I have a webapp that is running on two load balanced tomcat servers. What's the best way for the app to determine which server it's running on?
While I can tell from a sessionid which server it's running on (as .jvm1 and .jvm2 get appended), how can I get similar information in a background task (scheduled via Spring's @Scheduled annotation)?
Upvotes: 3
Views: 1373
Reputation: 308001
It might be overkill and if there's another way it's probably better, but you might be able to query the tomcat Engine MBean and get it's jvmRoute
property. The MBean is usually called Catalina:type=Engine
or Catalina:type=Engine,service=something
(see here for more details).
Upvotes: 1
Reputation: 3401
If you run your instance on different machines, you can simply get hostName InetAddress.getLocalHost().getCanonicalHostName()
Upvotes: 1