CommandA 75% CommandB 15% CommandC 10%
Question:-
The above Config File have some type of weighing to the Commands (execute CommandA 75% of the time, execute CommandB 15% of the time and execute Command C 10% of the time. Total weighing should add up to 100%.
Code that I wrote:-
I wrote a multithreading program in which I am reading the files line by line but not sure how should I do the above question in which this much percentage of random calls go to CommandA, and this much percentage of random calls go to CommandB and same with CommandC.
public static void main(String[] args) {
for (int i = 1; i <= threadSize; i++) {
new Thread(new ThreadTask(i)).start();
}
}
class ThreadTask implements Runnable {
private int id;
public ThreadTask(int id) {
this.id = id;
}
public synchronized void run() {
BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(new FileReader("C:\\testing\\Test.txt"));
while ((sCurrentLine = br.readLine()) != null) {
String[] s = sCurrentLine.split("\\s+");
for (String split : s) {
if(split.matches("\\d*"))
System.out.println(split);
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}

New Topic/Question
Reply




MultiQuote







|