This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Need help  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to see why declaring static final variable is NOT enough for singleton pattern.

For that I have created following 3 classes:



Running this code results in following exception.
Exception in thread "Thread-620" java.lang.ClassCastException: SingletonCheck cannot be cast to java.lang.Comparable
at java.util.concurrent.ConcurrentSkipListMap.comparable(ConcurrentSkipListMap.java:621)
at java.util.concurrent.ConcurrentSkipListMap.doPut(ConcurrentSkipListMap.java:862)
at java.util.concurrent.ConcurrentSkipListMap.putIfAbsent(ConcurrentSkipListMap.java:1893)
at java.util.concurrent.ConcurrentSkipListSet.add(ConcurrentSkipListSet.java:202)
at test3.ThreadRunner.run(ThreadRunner.java:15)
at java.lang.Thread.run(Thread.java:619)


Could someone help me in solving this error please?
Do I need to implement equals() method?

Regards,
Patrio
 
Patrio Jensen
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Changing from ConcurrentSkipListSet to CopyOnWriteArraySet did the trick. Need to see why it's failing for ConcurrentSkipListSet.
 
author and iconoclast
Sheriff
Posts: 24220
40
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the error message should be making that pretty clear, and you can confirm this by going to the Javadocs: objects put into a ConcurrentSkipListSet have to implement Comparable. TreeMap, TreeSet, and other sorted collections are the same way. You can generally supply a Comparator instance instead, if your class doesn't want to implement Comparable.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!