• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Simultaneous calling of methods

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic