This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Simultaneous calling of methods" Watch "Simultaneous calling of methods" New topic
Author

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
Bartender

Joined: Jan 28, 2003
Posts: 4165
    
  21

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.


Steve
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
 
Similar Threads
How to Change the File Name for Each Uploaded Files to the Socket Server?
Unable to populate String
GPRS + J2ME Related queires
File outputted has size zero
Writing to files using socket server