Jump to content


Photo

Ch 15 Testing Threads


  • Please log in to reply
1 reply to this topic

#1 asharkman

asharkman

    New Member

  • Members
  • Pip
  • 2 posts

Posted 23 April 2014 - 02:08 AM

Hi Guys,

I'm after doing the code magnets exercise and after double checking the code i almost never get the results that are displayed.
It's always slightly different
One: 96096
Two: 96097
One: 98099
Two: 98099
One: 97098
Two: 97098
I've tried longer and shorter sleep amounts but no avail. I've attached the code and I'd appreciate any help as it's got me stumped.

I just can't figure out how they're different. I've tried to step through it with eclipse and that's not working either.
Just seems to jump around. Anyone got any tips for debugging threaded apps?

Thank for any help at all,

Paul.


Paul.Attached File  TestThreads.txt   1.47KB   73 downloads

#2 asharkman

asharkman

    New Member

  • Members
  • Pip
  • 2 posts

Posted 23 April 2014 - 03:06 AM

Alright! I think i found it, still can't get the results in the book but at least they're consistant now.
I put synchronized in on the function, obviously that update was taking a long time and they were crossing over.
Strange to say the least but looks like that's what it was.

public synchronized void updateCounter(int add){
counter += add;
}




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users