Reputation: 1
I have a client sever program but I need my client to be able to listen for messages from the sever as it may send some at any time. I also need my client send information when needed to. What would be the best way to do this? I understand I'd probably need a thread.
Any help would be appreciated.
Upvotes: 0
Views: 208
Reputation: 39477
If this is the only thing your client will do, you don't need a separate thread.
Otherwise, yes, you need one background thread to handle these tasks which would
free the main thread to do other things.
To create a thread, the most basic way is to extend Thread
or implement Runnable
.
See also:
http://docs.oracle.com/javase/tutorial/essential/concurrency/
Upvotes: 2