O'Reilly Forums: Ch 15 Testing Threads - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Ch 15 Testing Threads Code magnets

#1 User is offline   asharkman 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 31-January 14

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.47K)
Number of downloads: 35
0

#2 User is offline   asharkman 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 31-January 14

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users