java - Assign argument to variables in multithreading -


i have written code send , receive files between 2 client , server want both functions in 1 program. wrote separate class containing send , receive functions. have declared 2 variables sendfilepath , receivefilepath. called method transfer(string sendfilename, string receivefilename) , assigned values these variables showing null.

how can this?

actually want send sendfilepath rf.receive(); , receivefilepath sf.send(); method how can done?

class transferfile implements runnable {         thread thread;      string sendfilepath, receivefilepath;     sendfile sf = new sendfile();     receivefile rf = new receivefile();      public void transferfilecreatethread(string name)     {         thread = new thread(this,name);         thread.start();     }     public void run()     {         rf.receive(sendfilepath);         sf.send(receivefilepath);     }      public void transfer(string sendfilename, string receivefilename)     {         try         {             sendfilepath = sendfilename;             receivefilepath = receivefilename;              transferfile t1 = new transferfile();             transferfile t2 = new transferfile();             t1.transferfilecreatethread(sendfilepath);             t2.transferfilecreatethread(receivefilepath);         }         catch(exception e)         {         }     } } 

here creating new object t1 , t2, not assigning values objects t1 , t2.

you can in way..

class transferfile implements runnable {         thread thread;      private string sendfilepath=null;     private string receivefilepath=null;     sendfile sf = new sendfile();     receivefile rf = new receivefile();      public void transferfilecreatethread(string name)     {         thread = new thread(this,name);         thread.start();     }     public void run()     {         rf.receive(sendfilepath);         sf.send(receivefilepath);     }     public void setsendfilepath(string filepath){          this.sendfilepath=filepath;     }     public void setreceivefilepath(string filepath){          this.receivefilepath=filepath;     }     public void transfer(string sendfilename, string receivefilename)     {         try         {             sendfilepath = sendfilename;             receivefilepath = receivefilename;              transferfile t1 = new transferfile();             t1.setsendfilepath(sendfilepath);             t1.setreceiverfilepath(receivefilepath);             transferfile t2 = new transferfile();             t1.setsendfilepath(sendfilepath);             t1.setreceiverfilepath(receivefilepath);             t1.transferfilecreatethread(sendfilepath);             t2.transferfilecreatethread(receivefilepath);         }         catch(exception e)         {         }     } } 

hope helps..

what thing can can call tranfer method on t1 , t2 asign values string objects.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -