• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Something I've Never Seen Before

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All,

I've been writing java from the beginning but this is something I've never seen before so I thought I'd ask. I have tried to not bog things down with too much information. I hope I am giving enough.

I have two classes: (1) CurrStateByStage and (2) Visitors.

When, I add a visitor, a Visitors list is retrieved and the Visitor is added to a list successfully. During processing, Visitor(s) are added repeatedly and the list should grow, but it does not. It always has a size of 0 before the add and a size of 1 afterward; and the Visitors object appears to be different one (based on its hashcode, which is not shown) upon each call even though the CurrStateByStage object is always the same as is its member mapByStage. I should be adding visitors to the same list instance each time.

What is happening to Visitors? Why apparently a new object at every iteration? Could it have anything to do with my having a map of lists? could it have anything to do with this code executing within a Hadoop reducer class?

I have used ArrayList extensively and have never seen behavior like this.

Relevant parts:




From the log file with comments added:

qq.mr.prime.val.CurrStateByStage@27958cc2 vv=[] // Note the reference id. Upon repeated calls it is always the same.
qq.mr.prime.val.Visitors: add=[]
qq.mr.prime.val.Visitors=[id=42322423 <irrelevant output here>] before=0 after=1 // Note the id. Note the before and after numbers are always 0 and 1 respectively.

qq.mr.prime.val.CurrStateByStage@27958cc2 vv=[] // Note the reference id. It it still the same.
qq.mr.prime.val.Visitors: add=[]
qq.mr.prime.val.Visitors=[id=42334683 <irrelevant output here>] before=0 after=1 // Note the id is different because we're adding a different visitor. Note the before and after numbers are still 0 and 1.

Thanks in advance.
 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch! You've been programming Java since the beginning, but have just found your way here? Well, I hope you'll stick around anyway, now that you've finally made it.

From the logs you've provided, it looks like CurrStateByStage is staying the same throughout the process, but you're getting two different Vistors objects. (Your comment on the log says you believe the IDs are different because the Visitor objects are different, but it looks to me like you're logging the ID of the Visitors (ArrayList subclass), not the the ID of the Visitor that you mean to add.) So, the upshot is that you've added one visitor to one visitor list and one to another, and so it's not surprising that each list contains one element. You need to figure out why your getVisitors(key) method is returning different lists each time.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Greg Charles wrote:You need to figure out why your getVisitors(key) method is returning different lists each time.



Indeed, that may be the code you need to show us.
 
It's never done THAT before. Explain it to me tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic