Jeff Verdegan wrote:Ralph makes some very good points. However, that doesn't mean all is lost. We may still be able to help. If you can provide an SSCCE that reproduces your problem, then somebody can probably help you figure out what's wrong. Getting it to reproduce can be tricky with multithreaded code. Even a small change (e.g., removal of superfluous stuff to get it down to a manageable size for a forum) can change how the threads interact. Still, if you can get it to happen say, one time in 5 or 10, then that may be enough.
I'll even stick my neck out and say that the problem you describe sounds like thread T1 is updating a variable, but T2 is not seeing the updates, and is continuing to work off of the old value, which is caused because you didn't make proper use of synchronization or volatile (or, once you understand the low-level stuff, java.util.concurrent.*).
spm Martino wrote:I suspect the threading issue also, but being new to Java, I don't know if it is my bad programming, or the thread hammering me.
If I send a DEPOSIT command of say DEPOSIT(1000), and println it, I see it add 1000 to the balance, and then forever continue to add 1000 to balance until I CTRL-C the program...
I have tried just starting 1 thread (even though I think java is starting its own without the one I start), doesn't resolve the issue..
If I go to the constructor of ever .java program involved and put in a getBalance(), deposit(1000), withdrawal(500), I get the correct results on the client side, I just don't get the results running it through the application threads, or perhaps my coding issues.
To do a great right, do a little wrong - shakepeare. twisted little ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|