This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads in state machine  RSS feed

 
mayank gupta
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to write an application for an entity where a state machine is maintained, so essentially, I can go from one state to the other only if the previous one is completed.
If the state is 1 a request is sent to the server. the client wait for the reply to come, only then does the client transitions to state 2. Is there any point in implementing the client using threads?


 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well since every Java program uses at least one Thread, I assume you mean "is there any point in creating a new Thread to handle the conversation".

Typically the answer is yes.

For any non-trivial use you are going to want to have one Thread which can respond to user input in addition to the one which is waiting for a reply. Otherwise the only control you would have when waiting would be killing the entire process.

Bill
 
mayank gupta
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Otherwise the only control you would have when waiting would be killing the entire process.

Could you please explain this in a little more detail. Maybe with an example.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!