Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threaded Application won't run.

 
Rob Brew
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What gives?

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65339
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps an expanded definition of "won't run" might be helpful.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your connect() method ever exit?
 
Rob Brew
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void run won't execute, and from that the rest of the program is started.
 
Rob Brew
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
connect() doesn't get called because void run() is never called.
 
Rob Brew
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ah, hang on.

I'm using NetBeans and was actually running ChatClient when i hit run.

Goes to stand in a corner.

Ignore this please.
 
Rob Spoor
Sheriff
Pie
Posts: 20753
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew is still right. Your connect() method contains a while (true) loop that only ends when an exception occurs, and therefore the entire method will only end when an exception occurs.

Other than that, you will overwrite reader and writer for every new connection. They should become local variables instead, which you then pass to the runnables:
Now each connection will have its own reader/writer pair and its own handling threads.
 
Rob Brew
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the same format for ChatServer i build ChatClient, both Server and Client send data but it doesn't noticeably get received.

ChatClient.java
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic