How to programmatically determine which (load-balanced) tomcat server is running webapp

I have a webapp that runs on two balanced tomcat load balanced servers. What is the best way for an application to determine which server it is running on?

So far, I can tell with sessionid which server it is running on (how .jvm1 and .jvm2 are added), how can I get similar information in a background task (scheduled using Spring @Scheduled annotations)?

+3
source share
2 answers

This may be redundant, and if there is another way, then this is probably better, but you can query mycat Engine MBean and get its property jvmRoute. An MBean is usually called Catalina:type=Engineor Catalina:type=Engine,service=something(see here for more details ).

+1
source

If you run your instance on different machines, you can just get hostName InetAddress.getLocalHost().getCanonicalHostName()

+1
source

All Articles