Doing a threading problem and I am not sure if this is how its supposed to be or if I coded incorrectly. From what I understand, threading should have multiple methods going at the same time and because of this they should be intertwined. My code is supposed to take a single char and repeat 1000 times but instead of having different variations of the two letters it goes "a" a thousand times, then "b" a thousand times. What is my issue?
Main Method
import java.util.*;
public class MainThread {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner answer = new Scanner(System.in);
System.out.println("Give me a single character: ");
char h = answer.next().charAt(0);
System.out.println("Give me another single character: ");
char a = answer.next().charAt(0);
MyThread t1 = new MyThread(h);
MyThread t2 = new MyThread(a);
t1.start(h);
t2.start(a);
answer.close();
}
}
my Threading class
import java.util.*;
public class MyThread extends Thread{
Scanner answer = new Scanner(System.in);
public MyThread(char x) {
// TODO Auto-generated constructor stub
}
public void Stored(char x){
System.out.println("Type a single letter here: ");
}
//modified run method
public void start(char x){
for(int i = 0; i < 1000; i++){
System.out.print(x);
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
Thread.yield();
}
}
}