Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Tomcat Users »

Re: How do you generate a unique number for each request across muliple tomcat instances?

Tom Ly

2003-12-16

Replies:

bump

Tom Ly <booshleeka@(protected)

Tim Funk wrote:Ideally use a string for uniqueness, not an int. For an int is too small
across a cluster.

To get a unique string, concatenate your IP address with
java.rmi.server.UID(), for example:
String guid = InetAddress.getLocalHost().getHostAddress() +
(new java.rmi.server.UID()).toString());

See the javadocs on UID for more info.

-Tim

Tom Ly wrote:

> I have an application where I need to generate a unique int for each request that comes in. I've got about 8 Tomcat instances running spread across four machines(two tomcat's each machine). It's pretty simple with one Tomcat, but with mulitple Tomcats it gets tricky. I tried using InetAddress to get the ip address of the current machine and use that to set the range for each tomcat(since the ip address will always be unique), but since I'm using Linux, it'll always return 127.0.0.1 as the ip address, so I can use class InetAddress. Any advice on what to do?



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)



---------------------------------
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard


---------------------------------
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
©2008 junlu.com - Jax Systems, LLC, U.S.A.