Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
updating and using String in multiple threads
I am attempting to create a basic chat program and I am having some difficulties as I am trying to use threads for it. There is a single Server object that listens for Client connects, and assigns each one to its own thread. The problem is that I'd like all threads to 'receive' any string generated by all clients, for outputting purposes.
Can I have an instance variable in my Server class that each thread can write to as well as outputting that variable if it has been outdated since last check, or is that just nonsense? A little new to threading here...
Thanks in advance,