• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
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: 24213
35
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!