You can make a tuple class (for 2 elements). As described here: https://stackoverflow.com/a/12328838/2236741
With this class you even have the hash calculation taking into account the two objects. Modify it to your reality if necessary.
In this case it would look like this:
Map<Integer, Tuple<Tratamento,Thread>> objs = new HashMap<Integer, Tuple<Tratamento,Thread>>();
You will probably have to have some kind of object that stores keys that have not yet been closed.
If more than one thread goes to Hashmap, then you need to use a thread-safe version called Concurrenthashmap.
Update - Example of use
Below is an example of how to use it. Note that I used Integer, String instead of Thread and Treatment.
HashMap<Integer, Tuple<Integer,String>> objs = new HashMap<Integer, Tuple<Integer, String>>();
objs.put(10,new Tuple<Integer, String>(150,"ABC"));
objs.put(11,new Tuple<Integer, String>(300,"DEF"));
Tuple<Integer,String> tuple = objs.get(10);
System.out.println(tuple.x);
System.out.println(tuple.y);
tuple = objs.get(11);
System.out.println(tuple.x);
System.out.println(tuple.y);
If you want, just change the attributes of the Tuple class from x and y to Treatment and Thread. However, your class will no longer be generic. If you only need it for this part of your code, switch to make it clear.
Hashmap does not solve your problem?
– Luis Henrique
I tried to use, but I have 2 objects from different classes. I don’t know if Hashmap supports something like.
– JLuann
In the initial answer I had written for you to use two Haspmaps, one for Treatment and one for Thread, however, both indexed with the same key. This is another way to do it, if you don’t want to use the suggestion of the Tuple class.
– cantoni
I liked the previous reply. I will try to use it in my code, thanks for sharing.
– JLuann