Re: Seeming Non-determinism in Java Programs

Endre Stølsvik <[email protected]> Mon, 7 Apr 2008 03:27:36 +0200
Newsgroups gmane.comp.windows.devel.java.advanced
Message-ID <[email protected]>
Randall R Schulz wrote:

> This is perplexing to me. How can multiple independent (but identical)
> invocations of the JVM produce highly varying executions?
>
> My first question is this: What phenomenon / dynamics can cause this
> sort of behavior? While I'm open to the possibility that it is a bug
> (permit me to say a _subtle_ bug), I'm experienced enough to know the
> proper implementation of equals() and hashCode(), e.g.

Something to do with concurrency and order (if you have more than one
thread in operation), so that insertion order in your different sets is
changed between runs, and/or that some objects' hashCodes basically
still are System.identityHashcode, so that even though the objects
creation order in regard to program execution order are in the exact
same order every time, they might still get different hashCodes
(although I've experienced that even huge application servers get the
exact same hashCode for some late-created object, as long as still only
the main thread is running).

>
> Has anyone else seen this sort of phenomenon? If so, how have you dealt
> with it?

I need a defined order on some ticket-thingies even if they have the
same "ticket value" (re: your repeated FOM values). I use a creation
sequence number as a last resort when comparing. But if the problem is
concurrency, I guess that would still give you different orders for
different runs.

Endre.

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com