Click here to Skip to main content
14,770,038 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have wrote a class that run the same class in the threads.

See code below

String outpiutFile1 = "c:\File1.txt";

String outpiutFile2 = "c:\File2.txt";

RunableThread run1 = new RunableThread(outpiutFile1);
Thread t1 = new Thread(run1);
t1.start();


RunableThread run2 = new RunableThread(outpiutFile2);
Thread t2 = new Thread(run2);
t2.start();


Question Why with this code the both thread t1 & t2 are writing in both files .

t1 logs events in both files
t2 logs events in both files
It seems like the multi threading create unique instance for run1 and run2 classes.
Posted
Updated 6-May-10 2:44am
v2
Comments
Richard MacCutchan 6-May-10 8:23am
   
Without seeing some more of your code it is impossible to offer a sensible suggestion.
Nagy Vilmos 9-May-10 5:44am
   
The important part here that is missing is the content of RunnableThread's run method.
j4v1 10-Sep-10 17:20pm
   
I agree, the Code of RunableThread is missing. Submit it, and there can be help...
krumia 11-Feb-12 23:04pm
   
Agreed. I don't see any problem in the code you have posted here. You should post the RunnableThread class' code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900