Hi. I have two methods in a class I made that I want to call simultaneously in Java. Example:
As you can see, only when a connection is connected then can the console start accepting command and this is what happened when I ran my program. I need the tcp side to keep listening and printing out whatever it have read from the socket and on the other hand, I need the console to accept any command the user may input into the console. How do I make both of them run at the same time ?
Well, you are right in posting the question here, Threads will be the solution to your problem, if you want to perform multiple tasks in parallel.
You showed us some code that does the task serially, what have you tried to do to make them run at the same time? Have you tried to create a threaded implementation? Have you read the Java Concurrency Tutorial?
If so, post some of the things you tried and let us know what problems you had, so we can help you fix them. If not, try to implement the the threaded version of your code yourself and ask specific questions when you run into problems, you will learn more that way.
Joined: Aug 07, 2008
Thanks for the advance and the link. It's helpful. Currently I seperated the 'console' and the tcp server into two classes and make them threads and they are working well enough for now.