You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Frank W. Zammetti" <fz...@omnytex.com> on 2005/03/18 16:35:32 UTC
Interesting problem...
Oh boy, I got a good one! It's only related to Struts in that the
application in question is Struts-based, so I hope no one minds a semi-OT
question...
Here's the situation... An app I wrote has a daemon thread that is spawned
at startup (from a Struts plugin) that does periodic background processing
tasks. This works great, never had a bit of trouble.
Now though, the app is moving from a single server to a clusted environment.
So, what's going to happen is that each server in the cluster will have
its own instance of the thread running on it. Not a huge problem except
that I have to be sure only one instance of the thread (i.e., one server
in the cluster) is executing concurrently.
The easy solution is just a database table that is checked when the thread
wakes up. If there is no entry in it, then there is no other instance
running, so it can write an entry to the table and go off and do its
thing.
I want to be extremely certain that no issues arise in terms of one
instance of the thread reading from the database while another instance is
writing, etc. So, aside from transactional database calls and row-level
locking, I want to do one more thing: I want the thread to sleep a random
number of seconds (1-300) at startup. This will ensure that, all the
database locking and such aside, the threads should all be offset from one
another in terms of when they run.
So, I need a random number generated when the thread starts up. As we all
know though, random number generation on most computers that don't have
something like a Brownian motion sensor attached stuck in a cup of boiling
coffee can't generate truly random numbers. So, in theory, what could
happen is that if all the servers in the cluster come up at the same time,
the threads could wind up running at the same time regardless of the
random sleep at the start! It might never happen in reality, small
fluctuations would probably offset them anyway, but I want to be more
certain than that.
So now we're at the crux of the problem...
I can't just seed the random number generator with the current time
because it concievably might not be random enough. So, I thought I could
just tally up the octets of the server's IP address and add that to the
current time. Then the seed on each server should be different enough.
But, there doesn't appear to be any way to get the server IP address
independant of a request, so I can't get at it in my plugin. Anyone know
differently?
Assuming that is the case, can anyone think of any other way to seed the
generator that would ensure a different value on different machines in the
cluster? There are some options like encoding the individual server names
in my app's config file with a different seed value for each, but that
makes maintenance a pain if a new server is added or one removed or
addresses simply changed.
Any ideas? Thanks!
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Interesting problem...
Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Commons ID has been in the sandbox for a year already? Ugh, someone get a
release out! :)
I think the solution I used is going to suffice nicely. I mean, in a
cluster each machine still has a unique IP address anyway, so that in and
of itself would have been enough. But, adding in the VMID and current
time makes it even MORE certain to be unique. Plus, in reading the
Commons ID page, that's very similar to how it is generating the UUIDs
anyway.
Thanks again, I very much appreciate the insight Martin!
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
On Fri, March 18, 2005 12:53 pm, Martin Wegner said:
> Frank,
>
> I was a little hinky myself about using Common ID in production. But I've
> been using it or over a year and it has performed admirably. We haven't
> seen any problems with the package.
>
> As for getting the MAC address I had to solve that problem about six
> months ago. I had to resort to Runtime.getRuntime().exec() (yuck). Here
> is where the madness all started:
>
> http://forum.java.sun.com/thread.jsp?forum=4&thread=245711
>
> It is ugly but it does indeed work. Until you run on a box that is not
> using English. And then you have the fun of boxes that have VPN software
> installed. And you have to watch out for disconnected media. Etc. Etc.
> Etc.
>
> Anyway, I got it work and now I pluck the MAC address from the local box.
> It is ugly but I had to do it.
>
> If anyone has a better way of getting the MAC address I would like to
> know.
>
>
> --Marty
>
> --- "Frank W. Zammetti" <fz...@omnytex.com> wrote:
>
>> Why do you think it wouldn't work? Does it sometimes return incorrect
>> information in some setups?
>>
>> I thought of doing some kind of mini-browser-type thing, but before I go
>> down that road I wanted to explore some simpler solutions. The Commons
>> ID
>> thing is very nice, but I'm not so sure I'm comfortable putting in
>> something that isn't actually released yet.
>>
>> That being said, what was on the site for it got me to thinking... I
>> think
>> if I do a combination of the sum of the MAC address digits + the current
>> time + the hashCode of the IP address, that is probably as random as I
>> need. But, if you know something about InetAddress that would make this
>> not work, I'm all ears :)
>>
>> Of course, I'm not sure how to get the MAC address yet, but one problem
>> at
>> a time...
>>
>> --
>> Frank W. Zammetti
>> Founder and Chief Software Architect
>> Omnytex Technologies
>> http://www.omnytex.com
>>
>> On Fri, March 18, 2005 12:14 pm, Dakota Jack said:
>> > InetAddress might not get the answer for you, Frank. I don't know
>> > what your setup is, but you can go to any ip address service outside
>> > your system and get a unique return address for your machines with a
>> > mini-browser.
>> >
>> > Jack
>> >
>> >
>> > On Fri, 18 Mar 2005 11:36:10 -0500 (EST), Frank W. Zammetti
>> > <fz...@omnytex.com> wrote:
>> >> Yes, I think InetAddress just might do the trick. Thank you Kris!
>> >>
>> >> --
>> >> Frank W. Zammetti
>> >> Founder and Chief Software Architect
>> >> Omnytex Technologies
>> >> http://www.omnytex.com
>> >>
>> >> On Fri, March 18, 2005 11:24 am, Kris Schneider said:
>> >> > Will InetAddress.getLocalHost() work for you?
>> >> > NetworkInterface.getNetworkInterfaces() might also be of interest.
>> Or,
>> >> you
>> >> > might want to create yourself an instance of java.rmi.dgc.VMID...
>> >> >
>> >> > Quoting "Frank W. Zammetti" <fz...@omnytex.com>:
>> >> >
>> >> >> Oh boy, I got a good one! It's only related to Struts in that the
>> >> >> application in question is Struts-based, so I hope no one minds a
>> >> >> semi-OT
>> >> >> question...
>> >> >>
>> >> >> Here's the situation... An app I wrote has a daemon thread that is
>> >> >> spawned
>> >> >> at startup (from a Struts plugin) that does periodic background
>> >> >> processing
>> >> >> tasks. This works great, never had a bit of trouble.
>> >> >>
>> >> >> Now though, the app is moving from a single server to a clusted
>> >> >> environment.
>> >> >>
>> >> >> So, what's going to happen is that each server in the cluster will
>> >> have
>> >> >> its own instance of the thread running on it. Not a huge problem
>> >> except
>> >> >> that I have to be sure only one instance of the thread (i.e., one
>> >> server
>> >> >> in the cluster) is executing concurrently.
>> >> >>
>> >> >> The easy solution is just a database table that is checked when
>> the
>> >> >> thread
>> >> >> wakes up. If there is no entry in it, then there is no other
>> >> instance
>> >> >> running, so it can write an entry to the table and go off and do
>> its
>> >> >> thing.
>> >> >>
>> >> >> I want to be extremely certain that no issues arise in terms of
>> one
>> >> >> instance of the thread reading from the database while another
>> >> instance
>> >> >> is
>> >> >> writing, etc. So, aside from transactional database calls and
>> >> row-level
>> >> >> locking, I want to do one more thing: I want the thread to sleep a
>> >> >> random
>> >> >> number of seconds (1-300) at startup. This will ensure that, all
>> the
>> >> >> database locking and such aside, the threads should all be offset
>> >> from
>> >> >> one
>> >> >> another in terms of when they run.
>> >> >>
>> >> >> So, I need a random number generated when the thread starts up.
>> As
>> >> we
>> >> >> all
>> >> >> know though, random number generation on most computers that don't
>> >> have
>> >> >> something like a Brownian motion sensor attached stuck in a cup of
>> >> >> boiling
>> >> >> coffee can't generate truly random numbers. So, in theory, what
>> >> could
>> >> >> happen is that if all the servers in the cluster come up at the
>> same
>> >> >> time,
>> >> >> the threads could wind up running at the same time regardless of
>> the
>> >> >> random sleep at the start! It might never happen in reality,
>> small
>> >> >> fluctuations would probably offset them anyway, but I want to be
>> more
>> >> >> certain than that.
>> >> >>
>> >> >> So now we're at the crux of the problem...
>> >> >>
>> >> >> I can't just seed the random number generator with the current
>> time
>> >> >> because it concievably might not be random enough. So, I thought
>> I
>> >> >> could
>> >> >> just tally up the octets of the server's IP address and add that
>> to
>> >> the
>> >> >> current time. Then the seed on each server should be different
>> >> enough.
>> >> >>
>> >> >> But, there doesn't appear to be any way to get the server IP
>> address
>> >> >> independant of a request, so I can't get at it in my plugin.
>> Anyone
>> >> >> know
>> >> >> differently?
>> >> >>
>> >> >> Assuming that is the case, can anyone think of any other way to
>> seed
>> >> the
>> >> >> generator that would ensure a different value on different
>> machines
>> >> in
>> >> >> the
>> >> >> cluster? There are some options like encoding the individual
>> server
>> >> >> names
>> >> >> in my app's config file with a different seed value for each, but
>> >> that
>> >> >> makes maintenance a pain if a new server is added or one removed
>> or
>> >> >> addresses simply changed.
>> >> >>
>> >> >> Any ideas? Thanks!
>> >> >>
>> >> >> --
>> >> >> Frank W. Zammetti
>> >> >> Founder and Chief Software Architect
>> >> >> Omnytex Technologies
>> >> >> http://www.omnytex.com
>> >> >
>> >> > --
>> >> > Kris Schneider <ma...@dotech.com>
>> >> > D.O.Tech <http://www.dotech.com/>
>> >> >
>> >> >
>> ---------------------------------------------------------------------
>> >> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> >> > For additional commands, e-mail: user-help@struts.apache.org
>> >> >
>> >> >
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> >> For additional commands, e-mail: user-help@struts.apache.org
>> >>
>> >>
>> >
>> >
>> > --
>> > "You can lead a horse to water but you cannot make it float on its
>> back."
>> > ~Dakota Jack~
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> > For additional commands, e-mail: user-help@struts.apache.org
>> >
>> >
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
[MASSIVELY OT AT THIS POINT] Re: Interesting problem...
Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
On Fri, March 18, 2005 1:46 pm, Kris Schneider said:
> Actually, I was thinking more along the lines of Radar's precog abilities.
> So,
> if you weren't aware the nick was coming, then it obviously doesn't fit
> ;-).
> Anyway, for better or worse, you've already got a namesake from the show.
> All
> we can hope for you is that you've got your own real-life Hot
> Lips...whatever
> form that may take... ;-)
Ah, didn't catch that. Very clever! :)
Actually, I always found Hot Lips rather unattractive, except in the movie
where she was quite nice for sure. Not on the show though.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Interesting problem...
Posted by Kris Schneider <kr...@dotech.com>.
Quoting "Frank W. Zammetti" <fz...@omnytex.com>:
> On Fri, March 18, 2005 1:30 pm, Kris Schneider said:
> > Quoting "Frank W. Zammetti" <fz...@omnytex.com>:
> >
> >> I've wanted a nickname all my life (aside from the explicitives some
> >> would
> >> use!)... never thought it's be Radar :)
> >
> > Then it probably shouldn't be ;-)
>
> Oh no, I opened my mouth with regard to my typing prowess of my own
> volition, and that was the catalyst for Radar so now I gotta suffer with
> it 'till the day I die. :) I can blame no one but myself!
Actually, I was thinking more along the lines of Radar's precog abilities. So,
if you weren't aware the nick was coming, then it obviously doesn't fit ;-).
Anyway, for better or worse, you've already got a namesake from the show. All
we can hope for you is that you've got your own real-life Hot Lips...whatever
form that may take... ;-)
> I don't mind... the only problem is now I gotta go get all new business
> cards printed up :)
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Interesting problem...
Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
On Fri, March 18, 2005 1:30 pm, Kris Schneider said:
> Quoting "Frank W. Zammetti" <fz...@omnytex.com>:
>
>> I've wanted a nickname all my life (aside from the explicitives some
>> would
>> use!)... never thought it's be Radar :)
>
> Then it probably shouldn't be ;-)
Oh no, I opened my mouth with regard to my typing prowess of my own
volition, and that was the catalyst for Radar so now I gotta suffer with
it 'till the day I die. :) I can blame no one but myself!
I don't mind... the only problem is now I gotta go get all new business
cards printed up :)
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Interesting problem...
Posted by Kris Schneider <kr...@dotech.com>.
Quoting "Frank W. Zammetti" <fz...@omnytex.com>:
> I've wanted a nickname all my life (aside from the explicitives some would
> use!)... never thought it's be Radar :)
Then it probably shouldn't be ;-)
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
>
> On Fri, March 18, 2005 1:09 pm, Dakota Jack said:
> > The class works, but I don't think it is what you want. Maybe it is.
> > Just don't have high expectations. I did and was disappointed. Just
> > trying to help you out, Radar! ///;-)
> >
> > Jack
> >
> >
> > On Fri, 18 Mar 2005 12:21:28 -0500 (EST), Frank W. Zammetti
> > <fz...@omnytex.com> wrote:
> >> Why do you think it wouldn't work? Does it sometimes return incorrect
> >> information in some setups?
> >>
> >> I thought of doing some kind of mini-browser-type thing, but before I go
> >> down that road I wanted to explore some simpler solutions. The Commons
> >> ID
> >> thing is very nice, but I'm not so sure I'm comfortable putting in
> >> something that isn't actually released yet.
> >>
> >> That being said, what was on the site for it got me to thinking... I
> >> think
> >> if I do a combination of the sum of the MAC address digits + the current
> >> time + the hashCode of the IP address, that is probably as random as I
> >> need. But, if you know something about InetAddress that would make this
> >> not work, I'm all ears :)
> >>
> >> Of course, I'm not sure how to get the MAC address yet, but one problem
> >> at
> >> a time...
> >>
> >> --
> >> Frank W. Zammetti
> >> Founder and Chief Software Architect
> >> Omnytex Technologies
> >> http://www.omnytex.com
> >>
> >> On Fri, March 18, 2005 12:14 pm, Dakota Jack said:
> >> > InetAddress might not get the answer for you, Frank. I don't know
> >> > what your setup is, but you can go to any ip address service outside
> >> > your system and get a unique return address for your machines with a
> >> > mini-browser.
> >> >
> >> > Jack
> >> >
> >> >
> >> > On Fri, 18 Mar 2005 11:36:10 -0500 (EST), Frank W. Zammetti
> >> > <fz...@omnytex.com> wrote:
> >> >> Yes, I think InetAddress just might do the trick. Thank you Kris!
> >> >>
> >> >> --
> >> >> Frank W. Zammetti
> >> >> Founder and Chief Software Architect
> >> >> Omnytex Technologies
> >> >> http://www.omnytex.com
> >> >>
> >> >> On Fri, March 18, 2005 11:24 am, Kris Schneider said:
> >> >> > Will InetAddress.getLocalHost() work for you?
> >> >> > NetworkInterface.getNetworkInterfaces() might also be of interest.
> >> Or,
> >> >> you
> >> >> > might want to create yourself an instance of java.rmi.dgc.VMID...
> >> >> >
> >> >> > Quoting "Frank W. Zammetti" <fz...@omnytex.com>:
> >> >> >
> >> >> >> Oh boy, I got a good one! It's only related to Struts in that the
> >> >> >> application in question is Struts-based, so I hope no one minds a
> >> >> >> semi-OT
> >> >> >> question...
> >> >> >>
> >> >> >> Here's the situation... An app I wrote has a daemon thread that is
> >> >> >> spawned
> >> >> >> at startup (from a Struts plugin) that does periodic background
> >> >> >> processing
> >> >> >> tasks. This works great, never had a bit of trouble.
> >> >> >>
> >> >> >> Now though, the app is moving from a single server to a clusted
> >> >> >> environment.
> >> >> >>
> >> >> >> So, what's going to happen is that each server in the cluster will
> >> >> have
> >> >> >> its own instance of the thread running on it. Not a huge problem
> >> >> except
> >> >> >> that I have to be sure only one instance of the thread (i.e., one
> >> >> server
> >> >> >> in the cluster) is executing concurrently.
> >> >> >>
> >> >> >> The easy solution is just a database table that is checked when
> >> the
> >> >> >> thread
> >> >> >> wakes up. If there is no entry in it, then there is no other
> >> >> instance
> >> >> >> running, so it can write an entry to the table and go off and do
> >> its
> >> >> >> thing.
> >> >> >>
> >> >> >> I want to be extremely certain that no issues arise in terms of
> >> one
> >> >> >> instance of the thread reading from the database while another
> >> >> instance
> >> >> >> is
> >> >> >> writing, etc. So, aside from transactional database calls and
> >> >> row-level
> >> >> >> locking, I want to do one more thing: I want the thread to sleep a
> >> >> >> random
> >> >> >> number of seconds (1-300) at startup. This will ensure that, all
> >> the
> >> >> >> database locking and such aside, the threads should all be offset
> >> >> from
> >> >> >> one
> >> >> >> another in terms of when they run.
> >> >> >>
> >> >> >> So, I need a random number generated when the thread starts up.
> >> As
> >> >> we
> >> >> >> all
> >> >> >> know though, random number generation on most computers that don't
> >> >> have
> >> >> >> something like a Brownian motion sensor attached stuck in a cup of
> >> >> >> boiling
> >> >> >> coffee can't generate truly random numbers. So, in theory, what
> >> >> could
> >> >> >> happen is that if all the servers in the cluster come up at the
> >> same
> >> >> >> time,
> >> >> >> the threads could wind up running at the same time regardless of
> >> the
> >> >> >> random sleep at the start! It might never happen in reality,
> >> small
> >> >> >> fluctuations would probably offset them anyway, but I want to be
> >> more
> >> >> >> certain than that.
> >> >> >>
> >> >> >> So now we're at the crux of the problem...
> >> >> >>
> >> >> >> I can't just seed the random number generator with the current
> >> time
> >> >> >> because it concievably might not be random enough. So, I thought
> >> I
> >> >> >> could
> >> >> >> just tally up the octets of the server's IP address and add that
> >> to
> >> >> the
> >> >> >> current time. Then the seed on each server should be different
> >> >> enough.
> >> >> >>
> >> >> >> But, there doesn't appear to be any way to get the server IP
> >> address
> >> >> >> independant of a request, so I can't get at it in my plugin.
> >> Anyone
> >> >> >> know
> >> >> >> differently?
> >> >> >>
> >> >> >> Assuming that is the case, can anyone think of any other way to
> >> seed
> >> >> the
> >> >> >> generator that would ensure a different value on different
> >> machines
> >> >> in
> >> >> >> the
> >> >> >> cluster? There are some options like encoding the individual
> >> server
> >> >> >> names
> >> >> >> in my app's config file with a different seed value for each, but
> >> >> that
> >> >> >> makes maintenance a pain if a new server is added or one removed
> >> or
> >> >> >> addresses simply changed.
> >> >> >>
> >> >> >> Any ideas? Thanks!
> >> >> >>
> >> >> >> --
> >> >> >> Frank W. Zammetti
> >> >> >> Founder and Chief Software Architect
> >> >> >> Omnytex Technologies
> >> >> >> http://www.omnytex.com
> >> >> >
> >> >> > --
> >> >> > Kris Schneider <ma...@dotech.com>
> >> >> > D.O.Tech <http://www.dotech.com/>
> >> >> >
> >> >> >
> ---------------------------------------------------------------------
> >> >> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> >> > For additional commands, e-mail: user-help@struts.apache.org
> >> >> >
> >> >> >
> >> >>
> >> >> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> >> For additional commands, e-mail: user-help@struts.apache.org
> >> >>
> >> >>
> >> >
> >> >
> >> > --
> >> > "You can lead a horse to water but you cannot make it float on its
> >> back."
> >> > ~Dakota Jack~
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> > For additional commands, e-mail: user-help@struts.apache.org
> >> >
> >> >
> >>
> >>
> >
> >
> > --
> > "You can lead a horse to water but you cannot make it float on its back."
> > ~Dakota Jack~
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
[OR] Re: Interesting problem...
Posted by Dakota Jack <da...@gmail.com>.
///;-)
On Fri, 18 Mar 2005 13:22:01 -0500 (EST), Frank W. Zammetti
<fz...@omnytex.com> wrote:
> I've wanted a nickname all my life (aside from the explicitives some would
> use!)... never thought it's be Radar :)
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
>
> On Fri, March 18, 2005 1:09 pm, Dakota Jack said:
> > The class works, but I don't think it is what you want. Maybe it is.
> > Just don't have high expectations. I did and was disappointed. Just
> > trying to help you out, Radar! ///;-)
> >
> > Jack
--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Interesting problem...
Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
I've wanted a nickname all my life (aside from the explicitives some would
use!)... never thought it's be Radar :)
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
On Fri, March 18, 2005 1:09 pm, Dakota Jack said:
> The class works, but I don't think it is what you want. Maybe it is.
> Just don't have high expectations. I did and was disappointed. Just
> trying to help you out, Radar! ///;-)
>
> Jack
>
>
> On Fri, 18 Mar 2005 12:21:28 -0500 (EST), Frank W. Zammetti
> <fz...@omnytex.com> wrote:
>> Why do you think it wouldn't work? Does it sometimes return incorrect
>> information in some setups?
>>
>> I thought of doing some kind of mini-browser-type thing, but before I go
>> down that road I wanted to explore some simpler solutions. The Commons
>> ID
>> thing is very nice, but I'm not so sure I'm comfortable putting in
>> something that isn't actually released yet.
>>
>> That being said, what was on the site for it got me to thinking... I
>> think
>> if I do a combination of the sum of the MAC address digits + the current
>> time + the hashCode of the IP address, that is probably as random as I
>> need. But, if you know something about InetAddress that would make this
>> not work, I'm all ears :)
>>
>> Of course, I'm not sure how to get the MAC address yet, but one problem
>> at
>> a time...
>>
>> --
>> Frank W. Zammetti
>> Founder and Chief Software Architect
>> Omnytex Technologies
>> http://www.omnytex.com
>>
>> On Fri, March 18, 2005 12:14 pm, Dakota Jack said:
>> > InetAddress might not get the answer for you, Frank. I don't know
>> > what your setup is, but you can go to any ip address service outside
>> > your system and get a unique return address for your machines with a
>> > mini-browser.
>> >
>> > Jack
>> >
>> >
>> > On Fri, 18 Mar 2005 11:36:10 -0500 (EST), Frank W. Zammetti
>> > <fz...@omnytex.com> wrote:
>> >> Yes, I think InetAddress just might do the trick. Thank you Kris!
>> >>
>> >> --
>> >> Frank W. Zammetti
>> >> Founder and Chief Software Architect
>> >> Omnytex Technologies
>> >> http://www.omnytex.com
>> >>
>> >> On Fri, March 18, 2005 11:24 am, Kris Schneider said:
>> >> > Will InetAddress.getLocalHost() work for you?
>> >> > NetworkInterface.getNetworkInterfaces() might also be of interest.
>> Or,
>> >> you
>> >> > might want to create yourself an instance of java.rmi.dgc.VMID...
>> >> >
>> >> > Quoting "Frank W. Zammetti" <fz...@omnytex.com>:
>> >> >
>> >> >> Oh boy, I got a good one! It's only related to Struts in that the
>> >> >> application in question is Struts-based, so I hope no one minds a
>> >> >> semi-OT
>> >> >> question...
>> >> >>
>> >> >> Here's the situation... An app I wrote has a daemon thread that is
>> >> >> spawned
>> >> >> at startup (from a Struts plugin) that does periodic background
>> >> >> processing
>> >> >> tasks. This works great, never had a bit of trouble.
>> >> >>
>> >> >> Now though, the app is moving from a single server to a clusted
>> >> >> environment.
>> >> >>
>> >> >> So, what's going to happen is that each server in the cluster will
>> >> have
>> >> >> its own instance of the thread running on it. Not a huge problem
>> >> except
>> >> >> that I have to be sure only one instance of the thread (i.e., one
>> >> server
>> >> >> in the cluster) is executing concurrently.
>> >> >>
>> >> >> The easy solution is just a database table that is checked when
>> the
>> >> >> thread
>> >> >> wakes up. If there is no entry in it, then there is no other
>> >> instance
>> >> >> running, so it can write an entry to the table and go off and do
>> its
>> >> >> thing.
>> >> >>
>> >> >> I want to be extremely certain that no issues arise in terms of
>> one
>> >> >> instance of the thread reading from the database while another
>> >> instance
>> >> >> is
>> >> >> writing, etc. So, aside from transactional database calls and
>> >> row-level
>> >> >> locking, I want to do one more thing: I want the thread to sleep a
>> >> >> random
>> >> >> number of seconds (1-300) at startup. This will ensure that, all
>> the
>> >> >> database locking and such aside, the threads should all be offset
>> >> from
>> >> >> one
>> >> >> another in terms of when they run.
>> >> >>
>> >> >> So, I need a random number generated when the thread starts up.
>> As
>> >> we
>> >> >> all
>> >> >> know though, random number generation on most computers that don't
>> >> have
>> >> >> something like a Brownian motion sensor attached stuck in a cup of
>> >> >> boiling
>> >> >> coffee can't generate truly random numbers. So, in theory, what
>> >> could
>> >> >> happen is that if all the servers in the cluster come up at the
>> same
>> >> >> time,
>> >> >> the threads could wind up running at the same time regardless of
>> the
>> >> >> random sleep at the start! It might never happen in reality,
>> small
>> >> >> fluctuations would probably offset them anyway, but I want to be
>> more
>> >> >> certain than that.
>> >> >>
>> >> >> So now we're at the crux of the problem...
>> >> >>
>> >> >> I can't just seed the random number generator with the current
>> time
>> >> >> because it concievably might not be random enough. So, I thought
>> I
>> >> >> could
>> >> >> just tally up the octets of the server's IP address and add that
>> to
>> >> the
>> >> >> current time. Then the seed on each server should be different
>> >> enough.
>> >> >>
>> >> >> But, there doesn't appear to be any way to get the server IP
>> address
>> >> >> independant of a request, so I can't get at it in my plugin.
>> Anyone
>> >> >> know
>> >> >> differently?
>> >> >>
>> >> >> Assuming that is the case, can anyone think of any other way to
>> seed
>> >> the
>> >> >> generator that would ensure a different value on different
>> machines
>> >> in
>> >> >> the
>> >> >> cluster? There are some options like encoding the individual
>> server
>> >> >> names
>> >> >> in my app's config file with a different seed value for each, but
>> >> that
>> >> >> makes maintenance a pain if a new server is added or one removed
>> or
>> >> >> addresses simply changed.
>> >> >>
>> >> >> Any ideas? Thanks!
>> >> >>
>> >> >> --
>> >> >> Frank W. Zammetti
>> >> >> Founder and Chief Software Architect
>> >> >> Omnytex Technologies
>> >> >> http://www.omnytex.com
>> >> >
>> >> > --
>> >> > Kris Schneider <ma...@dotech.com>
>> >> > D.O.Tech <http://www.dotech.com/>
>> >> >
>> >> > ---------------------------------------------------------------------
>> >> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> >> > For additional commands, e-mail: user-help@struts.apache.org
>> >> >
>> >> >
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> >> For additional commands, e-mail: user-help@struts.apache.org
>> >>
>> >>
>> >
>> >
>> > --
>> > "You can lead a horse to water but you cannot make it float on its
>> back."
>> > ~Dakota Jack~
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> > For additional commands, e-mail: user-help@struts.apache.org
>> >
>> >
>>
>>
>
>
> --
> "You can lead a horse to water but you cannot make it float on its back."
> ~Dakota Jack~
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Interesting problem...
Posted by Dakota Jack <da...@gmail.com>.
The class works, but I don't think it is what you want. Maybe it is.
Just don't have high expectations. I did and was disappointed. Just
trying to help you out, Radar! ///;-)
Jack
On Fri, 18 Mar 2005 12:21:28 -0500 (EST), Frank W. Zammetti
<fz...@omnytex.com> wrote:
> Why do you think it wouldn't work? Does it sometimes return incorrect
> information in some setups?
>
> I thought of doing some kind of mini-browser-type thing, but before I go
> down that road I wanted to explore some simpler solutions. The Commons ID
> thing is very nice, but I'm not so sure I'm comfortable putting in
> something that isn't actually released yet.
>
> That being said, what was on the site for it got me to thinking... I think
> if I do a combination of the sum of the MAC address digits + the current
> time + the hashCode of the IP address, that is probably as random as I
> need. But, if you know something about InetAddress that would make this
> not work, I'm all ears :)
>
> Of course, I'm not sure how to get the MAC address yet, but one problem at
> a time...
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
>
> On Fri, March 18, 2005 12:14 pm, Dakota Jack said:
> > InetAddress might not get the answer for you, Frank. I don't know
> > what your setup is, but you can go to any ip address service outside
> > your system and get a unique return address for your machines with a
> > mini-browser.
> >
> > Jack
> >
> >
> > On Fri, 18 Mar 2005 11:36:10 -0500 (EST), Frank W. Zammetti
> > <fz...@omnytex.com> wrote:
> >> Yes, I think InetAddress just might do the trick. Thank you Kris!
> >>
> >> --
> >> Frank W. Zammetti
> >> Founder and Chief Software Architect
> >> Omnytex Technologies
> >> http://www.omnytex.com
> >>
> >> On Fri, March 18, 2005 11:24 am, Kris Schneider said:
> >> > Will InetAddress.getLocalHost() work for you?
> >> > NetworkInterface.getNetworkInterfaces() might also be of interest. Or,
> >> you
> >> > might want to create yourself an instance of java.rmi.dgc.VMID...
> >> >
> >> > Quoting "Frank W. Zammetti" <fz...@omnytex.com>:
> >> >
> >> >> Oh boy, I got a good one! It's only related to Struts in that the
> >> >> application in question is Struts-based, so I hope no one minds a
> >> >> semi-OT
> >> >> question...
> >> >>
> >> >> Here's the situation... An app I wrote has a daemon thread that is
> >> >> spawned
> >> >> at startup (from a Struts plugin) that does periodic background
> >> >> processing
> >> >> tasks. This works great, never had a bit of trouble.
> >> >>
> >> >> Now though, the app is moving from a single server to a clusted
> >> >> environment.
> >> >>
> >> >> So, what's going to happen is that each server in the cluster will
> >> have
> >> >> its own instance of the thread running on it. Not a huge problem
> >> except
> >> >> that I have to be sure only one instance of the thread (i.e., one
> >> server
> >> >> in the cluster) is executing concurrently.
> >> >>
> >> >> The easy solution is just a database table that is checked when the
> >> >> thread
> >> >> wakes up. If there is no entry in it, then there is no other
> >> instance
> >> >> running, so it can write an entry to the table and go off and do its
> >> >> thing.
> >> >>
> >> >> I want to be extremely certain that no issues arise in terms of one
> >> >> instance of the thread reading from the database while another
> >> instance
> >> >> is
> >> >> writing, etc. So, aside from transactional database calls and
> >> row-level
> >> >> locking, I want to do one more thing: I want the thread to sleep a
> >> >> random
> >> >> number of seconds (1-300) at startup. This will ensure that, all the
> >> >> database locking and such aside, the threads should all be offset
> >> from
> >> >> one
> >> >> another in terms of when they run.
> >> >>
> >> >> So, I need a random number generated when the thread starts up. As
> >> we
> >> >> all
> >> >> know though, random number generation on most computers that don't
> >> have
> >> >> something like a Brownian motion sensor attached stuck in a cup of
> >> >> boiling
> >> >> coffee can't generate truly random numbers. So, in theory, what
> >> could
> >> >> happen is that if all the servers in the cluster come up at the same
> >> >> time,
> >> >> the threads could wind up running at the same time regardless of the
> >> >> random sleep at the start! It might never happen in reality, small
> >> >> fluctuations would probably offset them anyway, but I want to be more
> >> >> certain than that.
> >> >>
> >> >> So now we're at the crux of the problem...
> >> >>
> >> >> I can't just seed the random number generator with the current time
> >> >> because it concievably might not be random enough. So, I thought I
> >> >> could
> >> >> just tally up the octets of the server's IP address and add that to
> >> the
> >> >> current time. Then the seed on each server should be different
> >> enough.
> >> >>
> >> >> But, there doesn't appear to be any way to get the server IP address
> >> >> independant of a request, so I can't get at it in my plugin. Anyone
> >> >> know
> >> >> differently?
> >> >>
> >> >> Assuming that is the case, can anyone think of any other way to seed
> >> the
> >> >> generator that would ensure a different value on different machines
> >> in
> >> >> the
> >> >> cluster? There are some options like encoding the individual server
> >> >> names
> >> >> in my app's config file with a different seed value for each, but
> >> that
> >> >> makes maintenance a pain if a new server is added or one removed or
> >> >> addresses simply changed.
> >> >>
> >> >> Any ideas? Thanks!
> >> >>
> >> >> --
> >> >> Frank W. Zammetti
> >> >> Founder and Chief Software Architect
> >> >> Omnytex Technologies
> >> >> http://www.omnytex.com
> >> >
> >> > --
> >> > Kris Schneider <ma...@dotech.com>
> >> > D.O.Tech <http://www.dotech.com/>
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> > For additional commands, e-mail: user-help@struts.apache.org
> >> >
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> >
> > --
> > "You can lead a horse to water but you cannot make it float on its back."
> > ~Dakota Jack~
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Interesting problem...
Posted by Martin Wegner <ma...@yahoo.com>.
Frank,
I was a little hinky myself about using Common ID in production. But I've
been using it or over a year and it has performed admirably. We haven't
seen any problems with the package.
As for getting the MAC address I had to solve that problem about six
months ago. I had to resort to Runtime.getRuntime().exec() (yuck). Here
is where the madness all started:
http://forum.java.sun.com/thread.jsp?forum=4&thread=245711
It is ugly but it does indeed work. Until you run on a box that is not
using English. And then you have the fun of boxes that have VPN software
installed. And you have to watch out for disconnected media. Etc. Etc.
Etc.
Anyway, I got it work and now I pluck the MAC address from the local box.
It is ugly but I had to do it.
If anyone has a better way of getting the MAC address I would like to
know.
--Marty
--- "Frank W. Zammetti" <fz...@omnytex.com> wrote:
> Why do you think it wouldn't work? Does it sometimes return incorrect
> information in some setups?
>
> I thought of doing some kind of mini-browser-type thing, but before I go
> down that road I wanted to explore some simpler solutions. The Commons
> ID
> thing is very nice, but I'm not so sure I'm comfortable putting in
> something that isn't actually released yet.
>
> That being said, what was on the site for it got me to thinking... I
> think
> if I do a combination of the sum of the MAC address digits + the current
> time + the hashCode of the IP address, that is probably as random as I
> need. But, if you know something about InetAddress that would make this
> not work, I'm all ears :)
>
> Of course, I'm not sure how to get the MAC address yet, but one problem
> at
> a time...
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
>
> On Fri, March 18, 2005 12:14 pm, Dakota Jack said:
> > InetAddress might not get the answer for you, Frank. I don't know
> > what your setup is, but you can go to any ip address service outside
> > your system and get a unique return address for your machines with a
> > mini-browser.
> >
> > Jack
> >
> >
> > On Fri, 18 Mar 2005 11:36:10 -0500 (EST), Frank W. Zammetti
> > <fz...@omnytex.com> wrote:
> >> Yes, I think InetAddress just might do the trick. Thank you Kris!
> >>
> >> --
> >> Frank W. Zammetti
> >> Founder and Chief Software Architect
> >> Omnytex Technologies
> >> http://www.omnytex.com
> >>
> >> On Fri, March 18, 2005 11:24 am, Kris Schneider said:
> >> > Will InetAddress.getLocalHost() work for you?
> >> > NetworkInterface.getNetworkInterfaces() might also be of interest.
> Or,
> >> you
> >> > might want to create yourself an instance of java.rmi.dgc.VMID...
> >> >
> >> > Quoting "Frank W. Zammetti" <fz...@omnytex.com>:
> >> >
> >> >> Oh boy, I got a good one! It's only related to Struts in that the
> >> >> application in question is Struts-based, so I hope no one minds a
> >> >> semi-OT
> >> >> question...
> >> >>
> >> >> Here's the situation... An app I wrote has a daemon thread that is
> >> >> spawned
> >> >> at startup (from a Struts plugin) that does periodic background
> >> >> processing
> >> >> tasks. This works great, never had a bit of trouble.
> >> >>
> >> >> Now though, the app is moving from a single server to a clusted
> >> >> environment.
> >> >>
> >> >> So, what's going to happen is that each server in the cluster will
> >> have
> >> >> its own instance of the thread running on it. Not a huge problem
> >> except
> >> >> that I have to be sure only one instance of the thread (i.e., one
> >> server
> >> >> in the cluster) is executing concurrently.
> >> >>
> >> >> The easy solution is just a database table that is checked when
> the
> >> >> thread
> >> >> wakes up. If there is no entry in it, then there is no other
> >> instance
> >> >> running, so it can write an entry to the table and go off and do
> its
> >> >> thing.
> >> >>
> >> >> I want to be extremely certain that no issues arise in terms of
> one
> >> >> instance of the thread reading from the database while another
> >> instance
> >> >> is
> >> >> writing, etc. So, aside from transactional database calls and
> >> row-level
> >> >> locking, I want to do one more thing: I want the thread to sleep a
> >> >> random
> >> >> number of seconds (1-300) at startup. This will ensure that, all
> the
> >> >> database locking and such aside, the threads should all be offset
> >> from
> >> >> one
> >> >> another in terms of when they run.
> >> >>
> >> >> So, I need a random number generated when the thread starts up.
> As
> >> we
> >> >> all
> >> >> know though, random number generation on most computers that don't
> >> have
> >> >> something like a Brownian motion sensor attached stuck in a cup of
> >> >> boiling
> >> >> coffee can't generate truly random numbers. So, in theory, what
> >> could
> >> >> happen is that if all the servers in the cluster come up at the
> same
> >> >> time,
> >> >> the threads could wind up running at the same time regardless of
> the
> >> >> random sleep at the start! It might never happen in reality,
> small
> >> >> fluctuations would probably offset them anyway, but I want to be
> more
> >> >> certain than that.
> >> >>
> >> >> So now we're at the crux of the problem...
> >> >>
> >> >> I can't just seed the random number generator with the current
> time
> >> >> because it concievably might not be random enough. So, I thought
> I
> >> >> could
> >> >> just tally up the octets of the server's IP address and add that
> to
> >> the
> >> >> current time. Then the seed on each server should be different
> >> enough.
> >> >>
> >> >> But, there doesn't appear to be any way to get the server IP
> address
> >> >> independant of a request, so I can't get at it in my plugin.
> Anyone
> >> >> know
> >> >> differently?
> >> >>
> >> >> Assuming that is the case, can anyone think of any other way to
> seed
> >> the
> >> >> generator that would ensure a different value on different
> machines
> >> in
> >> >> the
> >> >> cluster? There are some options like encoding the individual
> server
> >> >> names
> >> >> in my app's config file with a different seed value for each, but
> >> that
> >> >> makes maintenance a pain if a new server is added or one removed
> or
> >> >> addresses simply changed.
> >> >>
> >> >> Any ideas? Thanks!
> >> >>
> >> >> --
> >> >> Frank W. Zammetti
> >> >> Founder and Chief Software Architect
> >> >> Omnytex Technologies
> >> >> http://www.omnytex.com
> >> >
> >> > --
> >> > Kris Schneider <ma...@dotech.com>
> >> > D.O.Tech <http://www.dotech.com/>
> >> >
> >> >
> ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> > For additional commands, e-mail: user-help@struts.apache.org
> >> >
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> >
> > --
> > "You can lead a horse to water but you cannot make it float on its
> back."
> > ~Dakota Jack~
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Interesting problem...
Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Why do you think it wouldn't work? Does it sometimes return incorrect
information in some setups?
I thought of doing some kind of mini-browser-type thing, but before I go
down that road I wanted to explore some simpler solutions. The Commons ID
thing is very nice, but I'm not so sure I'm comfortable putting in
something that isn't actually released yet.
That being said, what was on the site for it got me to thinking... I think
if I do a combination of the sum of the MAC address digits + the current
time + the hashCode of the IP address, that is probably as random as I
need. But, if you know something about InetAddress that would make this
not work, I'm all ears :)
Of course, I'm not sure how to get the MAC address yet, but one problem at
a time...
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
On Fri, March 18, 2005 12:14 pm, Dakota Jack said:
> InetAddress might not get the answer for you, Frank. I don't know
> what your setup is, but you can go to any ip address service outside
> your system and get a unique return address for your machines with a
> mini-browser.
>
> Jack
>
>
> On Fri, 18 Mar 2005 11:36:10 -0500 (EST), Frank W. Zammetti
> <fz...@omnytex.com> wrote:
>> Yes, I think InetAddress just might do the trick. Thank you Kris!
>>
>> --
>> Frank W. Zammetti
>> Founder and Chief Software Architect
>> Omnytex Technologies
>> http://www.omnytex.com
>>
>> On Fri, March 18, 2005 11:24 am, Kris Schneider said:
>> > Will InetAddress.getLocalHost() work for you?
>> > NetworkInterface.getNetworkInterfaces() might also be of interest. Or,
>> you
>> > might want to create yourself an instance of java.rmi.dgc.VMID...
>> >
>> > Quoting "Frank W. Zammetti" <fz...@omnytex.com>:
>> >
>> >> Oh boy, I got a good one! It's only related to Struts in that the
>> >> application in question is Struts-based, so I hope no one minds a
>> >> semi-OT
>> >> question...
>> >>
>> >> Here's the situation... An app I wrote has a daemon thread that is
>> >> spawned
>> >> at startup (from a Struts plugin) that does periodic background
>> >> processing
>> >> tasks. This works great, never had a bit of trouble.
>> >>
>> >> Now though, the app is moving from a single server to a clusted
>> >> environment.
>> >>
>> >> So, what's going to happen is that each server in the cluster will
>> have
>> >> its own instance of the thread running on it. Not a huge problem
>> except
>> >> that I have to be sure only one instance of the thread (i.e., one
>> server
>> >> in the cluster) is executing concurrently.
>> >>
>> >> The easy solution is just a database table that is checked when the
>> >> thread
>> >> wakes up. If there is no entry in it, then there is no other
>> instance
>> >> running, so it can write an entry to the table and go off and do its
>> >> thing.
>> >>
>> >> I want to be extremely certain that no issues arise in terms of one
>> >> instance of the thread reading from the database while another
>> instance
>> >> is
>> >> writing, etc. So, aside from transactional database calls and
>> row-level
>> >> locking, I want to do one more thing: I want the thread to sleep a
>> >> random
>> >> number of seconds (1-300) at startup. This will ensure that, all the
>> >> database locking and such aside, the threads should all be offset
>> from
>> >> one
>> >> another in terms of when they run.
>> >>
>> >> So, I need a random number generated when the thread starts up. As
>> we
>> >> all
>> >> know though, random number generation on most computers that don't
>> have
>> >> something like a Brownian motion sensor attached stuck in a cup of
>> >> boiling
>> >> coffee can't generate truly random numbers. So, in theory, what
>> could
>> >> happen is that if all the servers in the cluster come up at the same
>> >> time,
>> >> the threads could wind up running at the same time regardless of the
>> >> random sleep at the start! It might never happen in reality, small
>> >> fluctuations would probably offset them anyway, but I want to be more
>> >> certain than that.
>> >>
>> >> So now we're at the crux of the problem...
>> >>
>> >> I can't just seed the random number generator with the current time
>> >> because it concievably might not be random enough. So, I thought I
>> >> could
>> >> just tally up the octets of the server's IP address and add that to
>> the
>> >> current time. Then the seed on each server should be different
>> enough.
>> >>
>> >> But, there doesn't appear to be any way to get the server IP address
>> >> independant of a request, so I can't get at it in my plugin. Anyone
>> >> know
>> >> differently?
>> >>
>> >> Assuming that is the case, can anyone think of any other way to seed
>> the
>> >> generator that would ensure a different value on different machines
>> in
>> >> the
>> >> cluster? There are some options like encoding the individual server
>> >> names
>> >> in my app's config file with a different seed value for each, but
>> that
>> >> makes maintenance a pain if a new server is added or one removed or
>> >> addresses simply changed.
>> >>
>> >> Any ideas? Thanks!
>> >>
>> >> --
>> >> Frank W. Zammetti
>> >> Founder and Chief Software Architect
>> >> Omnytex Technologies
>> >> http://www.omnytex.com
>> >
>> > --
>> > Kris Schneider <ma...@dotech.com>
>> > D.O.Tech <http://www.dotech.com/>
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> > For additional commands, e-mail: user-help@struts.apache.org
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
> --
> "You can lead a horse to water but you cannot make it float on its back."
> ~Dakota Jack~
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Interesting problem...
Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
In the interest of giving back, here's what I wound up doing:
import java.net.InetAddress;
import java.rmi.dgc.VMID;
import java.util.GregorianCalendar;
int vmidHash = new VMID().hashCode();
long currentTime = new GregorianCalendar().getTimeInMillis();
int ipHash = InetAddress.getLocalHost().hashCode();
long seed = vmidHash + currentTime + ipHash;
Random randomGenerator = new Random(seed);
int seconds = randomGenerator.nextInt(200) + 100;
It's a combination of the VMID (which is supposed ot be unique for each
VM, but in actuality even on the SAME machine I'm getting a different
value each time, which is better for my use case) plus the current time
plus the machine's IP address. Even on the same machine this is
generating unique values for each of three threads I am spawning (I've
done it about 30 times now and have never seen a duplicate value). Does
the trick, I am happy. Thanks for all the insight everyone!
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
On Fri, March 18, 2005 12:14 pm, Dakota Jack said:
> InetAddress might not get the answer for you, Frank. I don't know
> what your setup is, but you can go to any ip address service outside
> your system and get a unique return address for your machines with a
> mini-browser.
>
> Jack
>
>
> On Fri, 18 Mar 2005 11:36:10 -0500 (EST), Frank W. Zammetti
> <fz...@omnytex.com> wrote:
>> Yes, I think InetAddress just might do the trick. Thank you Kris!
>>
>> --
>> Frank W. Zammetti
>> Founder and Chief Software Architect
>> Omnytex Technologies
>> http://www.omnytex.com
>>
>> On Fri, March 18, 2005 11:24 am, Kris Schneider said:
>> > Will InetAddress.getLocalHost() work for you?
>> > NetworkInterface.getNetworkInterfaces() might also be of interest. Or,
>> you
>> > might want to create yourself an instance of java.rmi.dgc.VMID...
>> >
>> > Quoting "Frank W. Zammetti" <fz...@omnytex.com>:
>> >
>> >> Oh boy, I got a good one! It's only related to Struts in that the
>> >> application in question is Struts-based, so I hope no one minds a
>> >> semi-OT
>> >> question...
>> >>
>> >> Here's the situation... An app I wrote has a daemon thread that is
>> >> spawned
>> >> at startup (from a Struts plugin) that does periodic background
>> >> processing
>> >> tasks. This works great, never had a bit of trouble.
>> >>
>> >> Now though, the app is moving from a single server to a clusted
>> >> environment.
>> >>
>> >> So, what's going to happen is that each server in the cluster will
>> have
>> >> its own instance of the thread running on it. Not a huge problem
>> except
>> >> that I have to be sure only one instance of the thread (i.e., one
>> server
>> >> in the cluster) is executing concurrently.
>> >>
>> >> The easy solution is just a database table that is checked when the
>> >> thread
>> >> wakes up. If there is no entry in it, then there is no other
>> instance
>> >> running, so it can write an entry to the table and go off and do its
>> >> thing.
>> >>
>> >> I want to be extremely certain that no issues arise in terms of one
>> >> instance of the thread reading from the database while another
>> instance
>> >> is
>> >> writing, etc. So, aside from transactional database calls and
>> row-level
>> >> locking, I want to do one more thing: I want the thread to sleep a
>> >> random
>> >> number of seconds (1-300) at startup. This will ensure that, all the
>> >> database locking and such aside, the threads should all be offset
>> from
>> >> one
>> >> another in terms of when they run.
>> >>
>> >> So, I need a random number generated when the thread starts up. As
>> we
>> >> all
>> >> know though, random number generation on most computers that don't
>> have
>> >> something like a Brownian motion sensor attached stuck in a cup of
>> >> boiling
>> >> coffee can't generate truly random numbers. So, in theory, what
>> could
>> >> happen is that if all the servers in the cluster come up at the same
>> >> time,
>> >> the threads could wind up running at the same time regardless of the
>> >> random sleep at the start! It might never happen in reality, small
>> >> fluctuations would probably offset them anyway, but I want to be more
>> >> certain than that.
>> >>
>> >> So now we're at the crux of the problem...
>> >>
>> >> I can't just seed the random number generator with the current time
>> >> because it concievably might not be random enough. So, I thought I
>> >> could
>> >> just tally up the octets of the server's IP address and add that to
>> the
>> >> current time. Then the seed on each server should be different
>> enough.
>> >>
>> >> But, there doesn't appear to be any way to get the server IP address
>> >> independant of a request, so I can't get at it in my plugin. Anyone
>> >> know
>> >> differently?
>> >>
>> >> Assuming that is the case, can anyone think of any other way to seed
>> the
>> >> generator that would ensure a different value on different machines
>> in
>> >> the
>> >> cluster? There are some options like encoding the individual server
>> >> names
>> >> in my app's config file with a different seed value for each, but
>> that
>> >> makes maintenance a pain if a new server is added or one removed or
>> >> addresses simply changed.
>> >>
>> >> Any ideas? Thanks!
>> >>
>> >> --
>> >> Frank W. Zammetti
>> >> Founder and Chief Software Architect
>> >> Omnytex Technologies
>> >> http://www.omnytex.com
>> >
>> > --
>> > Kris Schneider <ma...@dotech.com>
>> > D.O.Tech <http://www.dotech.com/>
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> > For additional commands, e-mail: user-help@struts.apache.org
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
> --
> "You can lead a horse to water but you cannot make it float on its back."
> ~Dakota Jack~
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Interesting problem...
Posted by Dakota Jack <da...@gmail.com>.
InetAddress might not get the answer for you, Frank. I don't know
what your setup is, but you can go to any ip address service outside
your system and get a unique return address for your machines with a
mini-browser.
Jack
On Fri, 18 Mar 2005 11:36:10 -0500 (EST), Frank W. Zammetti
<fz...@omnytex.com> wrote:
> Yes, I think InetAddress just might do the trick. Thank you Kris!
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
>
> On Fri, March 18, 2005 11:24 am, Kris Schneider said:
> > Will InetAddress.getLocalHost() work for you?
> > NetworkInterface.getNetworkInterfaces() might also be of interest. Or, you
> > might want to create yourself an instance of java.rmi.dgc.VMID...
> >
> > Quoting "Frank W. Zammetti" <fz...@omnytex.com>:
> >
> >> Oh boy, I got a good one! It's only related to Struts in that the
> >> application in question is Struts-based, so I hope no one minds a
> >> semi-OT
> >> question...
> >>
> >> Here's the situation... An app I wrote has a daemon thread that is
> >> spawned
> >> at startup (from a Struts plugin) that does periodic background
> >> processing
> >> tasks. This works great, never had a bit of trouble.
> >>
> >> Now though, the app is moving from a single server to a clusted
> >> environment.
> >>
> >> So, what's going to happen is that each server in the cluster will have
> >> its own instance of the thread running on it. Not a huge problem except
> >> that I have to be sure only one instance of the thread (i.e., one server
> >> in the cluster) is executing concurrently.
> >>
> >> The easy solution is just a database table that is checked when the
> >> thread
> >> wakes up. If there is no entry in it, then there is no other instance
> >> running, so it can write an entry to the table and go off and do its
> >> thing.
> >>
> >> I want to be extremely certain that no issues arise in terms of one
> >> instance of the thread reading from the database while another instance
> >> is
> >> writing, etc. So, aside from transactional database calls and row-level
> >> locking, I want to do one more thing: I want the thread to sleep a
> >> random
> >> number of seconds (1-300) at startup. This will ensure that, all the
> >> database locking and such aside, the threads should all be offset from
> >> one
> >> another in terms of when they run.
> >>
> >> So, I need a random number generated when the thread starts up. As we
> >> all
> >> know though, random number generation on most computers that don't have
> >> something like a Brownian motion sensor attached stuck in a cup of
> >> boiling
> >> coffee can't generate truly random numbers. So, in theory, what could
> >> happen is that if all the servers in the cluster come up at the same
> >> time,
> >> the threads could wind up running at the same time regardless of the
> >> random sleep at the start! It might never happen in reality, small
> >> fluctuations would probably offset them anyway, but I want to be more
> >> certain than that.
> >>
> >> So now we're at the crux of the problem...
> >>
> >> I can't just seed the random number generator with the current time
> >> because it concievably might not be random enough. So, I thought I
> >> could
> >> just tally up the octets of the server's IP address and add that to the
> >> current time. Then the seed on each server should be different enough.
> >>
> >> But, there doesn't appear to be any way to get the server IP address
> >> independant of a request, so I can't get at it in my plugin. Anyone
> >> know
> >> differently?
> >>
> >> Assuming that is the case, can anyone think of any other way to seed the
> >> generator that would ensure a different value on different machines in
> >> the
> >> cluster? There are some options like encoding the individual server
> >> names
> >> in my app's config file with a different seed value for each, but that
> >> makes maintenance a pain if a new server is added or one removed or
> >> addresses simply changed.
> >>
> >> Any ideas? Thanks!
> >>
> >> --
> >> Frank W. Zammetti
> >> Founder and Chief Software Architect
> >> Omnytex Technologies
> >> http://www.omnytex.com
> >
> > --
> > Kris Schneider <ma...@dotech.com>
> > D.O.Tech <http://www.dotech.com/>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Interesting problem...
Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Yes, I think InetAddress just might do the trick. Thank you Kris!
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
On Fri, March 18, 2005 11:24 am, Kris Schneider said:
> Will InetAddress.getLocalHost() work for you?
> NetworkInterface.getNetworkInterfaces() might also be of interest. Or, you
> might want to create yourself an instance of java.rmi.dgc.VMID...
>
> Quoting "Frank W. Zammetti" <fz...@omnytex.com>:
>
>> Oh boy, I got a good one! It's only related to Struts in that the
>> application in question is Struts-based, so I hope no one minds a
>> semi-OT
>> question...
>>
>> Here's the situation... An app I wrote has a daemon thread that is
>> spawned
>> at startup (from a Struts plugin) that does periodic background
>> processing
>> tasks. This works great, never had a bit of trouble.
>>
>> Now though, the app is moving from a single server to a clusted
>> environment.
>>
>> So, what's going to happen is that each server in the cluster will have
>> its own instance of the thread running on it. Not a huge problem except
>> that I have to be sure only one instance of the thread (i.e., one server
>> in the cluster) is executing concurrently.
>>
>> The easy solution is just a database table that is checked when the
>> thread
>> wakes up. If there is no entry in it, then there is no other instance
>> running, so it can write an entry to the table and go off and do its
>> thing.
>>
>> I want to be extremely certain that no issues arise in terms of one
>> instance of the thread reading from the database while another instance
>> is
>> writing, etc. So, aside from transactional database calls and row-level
>> locking, I want to do one more thing: I want the thread to sleep a
>> random
>> number of seconds (1-300) at startup. This will ensure that, all the
>> database locking and such aside, the threads should all be offset from
>> one
>> another in terms of when they run.
>>
>> So, I need a random number generated when the thread starts up. As we
>> all
>> know though, random number generation on most computers that don't have
>> something like a Brownian motion sensor attached stuck in a cup of
>> boiling
>> coffee can't generate truly random numbers. So, in theory, what could
>> happen is that if all the servers in the cluster come up at the same
>> time,
>> the threads could wind up running at the same time regardless of the
>> random sleep at the start! It might never happen in reality, small
>> fluctuations would probably offset them anyway, but I want to be more
>> certain than that.
>>
>> So now we're at the crux of the problem...
>>
>> I can't just seed the random number generator with the current time
>> because it concievably might not be random enough. So, I thought I
>> could
>> just tally up the octets of the server's IP address and add that to the
>> current time. Then the seed on each server should be different enough.
>>
>> But, there doesn't appear to be any way to get the server IP address
>> independant of a request, so I can't get at it in my plugin. Anyone
>> know
>> differently?
>>
>> Assuming that is the case, can anyone think of any other way to seed the
>> generator that would ensure a different value on different machines in
>> the
>> cluster? There are some options like encoding the individual server
>> names
>> in my app's config file with a different seed value for each, but that
>> makes maintenance a pain if a new server is added or one removed or
>> addresses simply changed.
>>
>> Any ideas? Thanks!
>>
>> --
>> Frank W. Zammetti
>> Founder and Chief Software Architect
>> Omnytex Technologies
>> http://www.omnytex.com
>
> --
> Kris Schneider <ma...@dotech.com>
> D.O.Tech <http://www.dotech.com/>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Interesting problem...
Posted by Kris Schneider <kr...@dotech.com>.
Will InetAddress.getLocalHost() work for you?
NetworkInterface.getNetworkInterfaces() might also be of interest. Or, you
might want to create yourself an instance of java.rmi.dgc.VMID...
Quoting "Frank W. Zammetti" <fz...@omnytex.com>:
> Oh boy, I got a good one! It's only related to Struts in that the
> application in question is Struts-based, so I hope no one minds a semi-OT
> question...
>
> Here's the situation... An app I wrote has a daemon thread that is spawned
> at startup (from a Struts plugin) that does periodic background processing
> tasks. This works great, never had a bit of trouble.
>
> Now though, the app is moving from a single server to a clusted environment.
>
> So, what's going to happen is that each server in the cluster will have
> its own instance of the thread running on it. Not a huge problem except
> that I have to be sure only one instance of the thread (i.e., one server
> in the cluster) is executing concurrently.
>
> The easy solution is just a database table that is checked when the thread
> wakes up. If there is no entry in it, then there is no other instance
> running, so it can write an entry to the table and go off and do its
> thing.
>
> I want to be extremely certain that no issues arise in terms of one
> instance of the thread reading from the database while another instance is
> writing, etc. So, aside from transactional database calls and row-level
> locking, I want to do one more thing: I want the thread to sleep a random
> number of seconds (1-300) at startup. This will ensure that, all the
> database locking and such aside, the threads should all be offset from one
> another in terms of when they run.
>
> So, I need a random number generated when the thread starts up. As we all
> know though, random number generation on most computers that don't have
> something like a Brownian motion sensor attached stuck in a cup of boiling
> coffee can't generate truly random numbers. So, in theory, what could
> happen is that if all the servers in the cluster come up at the same time,
> the threads could wind up running at the same time regardless of the
> random sleep at the start! It might never happen in reality, small
> fluctuations would probably offset them anyway, but I want to be more
> certain than that.
>
> So now we're at the crux of the problem...
>
> I can't just seed the random number generator with the current time
> because it concievably might not be random enough. So, I thought I could
> just tally up the octets of the server's IP address and add that to the
> current time. Then the seed on each server should be different enough.
>
> But, there doesn't appear to be any way to get the server IP address
> independant of a request, so I can't get at it in my plugin. Anyone know
> differently?
>
> Assuming that is the case, can anyone think of any other way to seed the
> generator that would ensure a different value on different machines in the
> cluster? There are some options like encoding the individual server names
> in my app's config file with a different seed value for each, but that
> makes maintenance a pain if a new server is added or one removed or
> addresses simply changed.
>
> Any ideas? Thanks!
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Interesting problem...
Posted by Rick Reumann <st...@reumann.net>.
I posed your question to a colleague of mine, because this problem is
way beyond my puny knowledge. Anyway, his response, for what it's worth:
>>>>>
My first instinct is to call this a Supremely Bad Idea. There WILL be
conflicts. You can bet on it. Best to have a single "maintenance"
process on a single host that fails over as needed. Alternatively, rely
on shared/exclusive table-level locking which is extremely efficient,
widely supported, and does not suffer from the issues that row-level
locking is famous for.
If the random number generator is still insisted upon, there are
standard solutions for seeding it. The java.security.SecureRandom class
uses host and network performance and latency metrics to seed itself.
While that might not be quite as well-seeded as a "pot of boiling
water", it's pretty darn close.
If that's not sufficient and you're running on a UNIX-style system
(Linux, BSD, Solaris, etc), you can read a block from /dev/random and
seed your generator with that. It's a system-level random state that
survives reboot.
Finally, you can seed it with a UUID. Most containers these days
provide some sort of UUID service, and if not then there are example
UUID generators all over the net.
<<<<<
<original uncommented post left below for reference:>
Frank W. Zammetti wrote the following on 3/18/2005 10:35 AM:
> Oh boy, I got a good one! It's only related to Struts in that the
> application in question is Struts-based, so I hope no one minds a semi-OT
> question...
>
> Here's the situation... An app I wrote has a daemon thread that is spawned
> at startup (from a Struts plugin) that does periodic background processing
> tasks. This works great, never had a bit of trouble.
>
> Now though, the app is moving from a single server to a clusted environment.
>
> So, what's going to happen is that each server in the cluster will have
> its own instance of the thread running on it. Not a huge problem except
> that I have to be sure only one instance of the thread (i.e., one server
> in the cluster) is executing concurrently.
>
> The easy solution is just a database table that is checked when the thread
> wakes up. If there is no entry in it, then there is no other instance
> running, so it can write an entry to the table and go off and do its
> thing.
>
> I want to be extremely certain that no issues arise in terms of one
> instance of the thread reading from the database while another instance is
> writing, etc. So, aside from transactional database calls and row-level
> locking, I want to do one more thing: I want the thread to sleep a random
> number of seconds (1-300) at startup. This will ensure that, all the
> database locking and such aside, the threads should all be offset from one
> another in terms of when they run.
>
> So, I need a random number generated when the thread starts up. As we all
> know though, random number generation on most computers that don't have
> something like a Brownian motion sensor attached stuck in a cup of boiling
> coffee can't generate truly random numbers. So, in theory, what could
> happen is that if all the servers in the cluster come up at the same time,
> the threads could wind up running at the same time regardless of the
> random sleep at the start! It might never happen in reality, small
> fluctuations would probably offset them anyway, but I want to be more
> certain than that.
>
> So now we're at the crux of the problem...
>
> I can't just seed the random number generator with the current time
> because it concievably might not be random enough. So, I thought I could
> just tally up the octets of the server's IP address and add that to the
> current time. Then the seed on each server should be different enough.
>
> But, there doesn't appear to be any way to get the server IP address
> independant of a request, so I can't get at it in my plugin. Anyone know
> differently?
>
> Assuming that is the case, can anyone think of any other way to seed the
> generator that would ensure a different value on different machines in the
> cluster? There are some options like encoding the individual server names
> in my app's config file with a different seed value for each, but that
> makes maintenance a pain if a new server is added or one removed or
> addresses simply changed.
>
> Any ideas? Thanks!
>
--
Rick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org