wood burning stoves
The moose likes Threads and Synchronization and the fly likes Simultaneous calling of methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Simultaneous calling of methods" Watch "Simultaneous calling of methods" New topic

Simultaneous calling of methods

Tay Thotheolh
Ranch Hand

Joined: Aug 07, 2008
Posts: 84
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 ?
Steve Luke

Joined: Jan 28, 2003
Posts: 4181

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.

Tay Thotheolh
Ranch Hand

Joined: Aug 07, 2008
Posts: 84
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.
I agree. Here's the link: http://aspose.com/file-tools
subject: Simultaneous calling of methods
It's not a secret anymore!