• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread Synchronization problem

 
Rahul Saple
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We guys are developing a P2P file sharing software(on LAN) and our program requires that we implement a multi-threaded client. I somewhere read on the forum about a multi threaded server but it doesnt work in my case (not on the client side.)The program runs properly when a single transfer is happening but if more then one file is getting downloaded the program seems to fall apart. Here's the code that provides the client side implementation of a file transfer.


Can you guys point out specifically where my program would need synchronization, since im a noob when it comes to threads. Thanks
 
Kevin Mangold
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your server creating and starting a new thread for each client?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see any synchronization issues right off, but there may be some tuning and tweaking opportunities.

When you use data=bufferedInput.read() how many bytes do you get at a time? Look at the JavaDoc to see if you can get more at a time.

When you use fileOutput.flush() you defeat the buffering. What happens if you take this line out?

Make sure to close the output, too.

When that -1 finally comes in at end of file, what do you do with it? Follow what happens to data. Does your output file look like you expect?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!