The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
August 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


RE: Threads and Sharing code

Posted by Kishori Sharan on August 10, 2000 at 2:03 PM

I don't know what you are trying to get using this program. But, I can tell you two things about this .
1. When you call "temp = jm.doCalculation(iSeed);" in run method all the time you are passing the same value to doCalculation ( ) method because the returned value from that method is never being stored again in iSeed instance variable. So it will print the same result all the time.
2. If you multipy iSeed in doCalculation() method by 1000 everytime and store the new value back in iSeed then after some time iSeed limit will overflow and it will start recycling the value. and you will notice stange numbers ( negative too ) .
Try restoring the return value of doCalculation () in iSeed and see the result. Your program code is valid and it will keep printing the same two lines ( one for each thread ). Because you haven't mentioned the exact problem you are trying to solve, I can tell only these two thing for now.


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us