Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get a unique instance of a class for each thread?  RSS feed

 
Ellen Zhao
Ranch Hand
Posts: 581
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Say I have a class called Lsas. There will be exactly 6 threads to get a unique instance of Lsas for each. I've made the constructor private and provided a public static Lsas getLsas() method. Thanks in advance.

regards,
Ellen
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the java.lang.ThreadLocal class. You could make your subclass of ThreadLocal an inner class of the class you're talking about, to give it access to the private constructor.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!