How to access the thread variable from outside of the thread , I have the hashmap inside the thread which I want to access from my main program or service.
public class Sample {
class Thread {
//private synchronized hashmap declared here
}
}
I want to access the hashmap declared in Thread in other class lets say Class Abc
The real problem with multiple threads accessing data is synchronization. If you have a map with data, make it a ConcurrentHashMap, and place it so that you can access it. Now you have access to the data in your map. Note that there could be other dependencies in your code that require more synchronization, but at least accessing the data in the map is safe.
Update: In your case I would do something like:
You can make it private, but there is much to say about inner classes and private that is out of scope of this question.