I’m creating two objects each within their own threads
Conversation c = new Conversation();
Thread t1 = new Thread(c);
t1.start();
HunterCom ns = new HunterCom(c);
Thread t2 = new Thread(ns);
t2.start();
I need to send the conversation object (c) a reference to the HunterCom object (ns)
Is there anyway to do this? Im strugeling because ns has not been created when I want to send it to c.
It sounds like you want c and ns to be referential to each other – i.e. c has a reference to ns, ns has a reference to c.
If that’s what you are asking for, you will need to put a setter in c that allows you to set the HunterCom object:
That said, if you are having reference cycles like this, it is generally an indication of an object model that needs review. If you peel the onion apart, you may be able to find a refactoring that eliminates the circular reference. This is worth doing, as it’ll make your code a lot easier to work with down the road.