Thread Synchronization problem
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.
class Downimplements Runnable
{
DataOutputStream dataOutput;
BufferedInputStream bufferedInput;
FileOutputStream fileOutput;
Socket down;
publicvoid run()
{
try
{
int data=0;
long i=0;
down=new Socket(user,9999);
dataOutput=new DataOutputStream(down.getOutputStream());//The following two lines send the file path to the server, to make the server's job easier rather than the server going for a file search
String msg=path.replace('\\','/');dataOutput.writeUTF(msg);
dataOutput.flush();
bufferedInput=new BufferedInputStream(down.getInputStream());
fileOutput=new FileOutputStream(new File(path));
while (data != -1)
{
data=bufferedInput.read();
fileOutput.write(data);
fileOutput.flush();
i++;
System.out.println("Transferring "+i);
}
System.out.println("File Transfer Done");
done=true;
}
catch (Exception e)
{
e.printStackTrace();
}
Can you guys point out specifically where my program would need synchronization, since im a noob when it comes to threads. Thanks

