My program is as below:
import java.io.*;
class MyThread implements Runnable{
int st,en;
LineNumberReader lmr1;
BufferedWriter bw;
MyThread(int s,int e){
st=s;
en=e;
}
public void run(){
try{
bw=new BufferedWriter(new FileWriter("EmpWritten.txt"));
lmr1=new LineNumberReader(new FileReader("out3.txt"));
String s=Thread.currentThread().getName();
lmr1.skip(st);
while(st++<en){
bw.write(s+"\t"+lmr1.readLine());
bw.newLine();
}
lmr1.close();
bw.close();
}
catch(Exception e){}
}
public static void main(String args[])throws Exception{
LineNumberReader lmr=new LineNumberReader(new FileReader("out3.txt"));
lmr.skip(Long.MAX_VALUE);
int num=lmr.getLineNumber();
int num1=num/3,num2=2*num1;
MyThread mt1=new MyThread(0,num1);
MyThread mt2=new MyThread(num1+1,num2);
MyThread mt3=new MyThread(num2+1,num);
Thread t1=new Thread(mt1);
Thread t2=new Thread(mt2);
Thread t3=new Thread(mt3);
t1.start();
t2.start();
t3.start();
lmr.close();
}
}
Input:
Commit ID Name Salary Department Number
Commit ID1 Name1 25100 Dept1
Commit ID2 Name2 25200 Dept2
Commit ID3 Name3 25300 Dept3
Commit ID4 Name4 25400 Dept4
Commit ID5 Name5 25500 Dept5
Commit ID6 Name6 25600 Dept6
Commit ID7 Name7 25700 Dept7
Commit ID8 Name8 25800 Dept8
Commit ID9 Name9 25900 Dept9
Commit ID10 Name10 26000 Dept10
output:
Thread-2 ID Name Salary Department Number
Thread-2 Commit ID1 Name1 25100 Dept1
Thread-2 Commit ID2 Name2 25200 Dept2
Thread-2 Commit ID3 Name3 25300 Dept3
Why don't other threads execute?What modifications need to be done to get the desired output?Efficient implementations of the program is also welcome.