Multithreading in Java
Multithreading in Java
public TaskThread(int n) {
this.n = n;
}
@Override
public void run() { //this need to be defined
System.out.println("Inside Thread's Run() with value " + n);
for (int i = n; i < n + 100; i++) {
System.out.print(i + " ");
}
System.out.println("\nExiting Thread's Run() that has value " + n);
}
}
public TaskRunnable(int n) {
this.n = n;
}
@Override
public void run() { //this need to be defined
System.out.println("Inside Runnable's Run() with value " + n);
for (int i = n; i < n + 100; i++) {
System.out.print(i + " ");
}
System.out.println("\nExiting Runnable's Run() that has value " + n);
}
}
t1.start();
t2.start();
}
}
//we can set priority[1,10] to a thread. 5 is by default
//t1.setPriority(7)
@Override
public void run() { //this need to be defined
System.out.println("\nInside Thread's Run() with value " + ch);
for (int i = 0; i < 100; i++) {
System.out.print(ch + " ");
}
System.out.println("\nExiting Thread's Run() that has value " + ch);
}
}
@Override
public void run() { //this need to be defined
System.out.println("\nInside Runnable's Run() with value " + ch);
for (int i = 0; i < 100; i++) {
System.out.print(ch + " ");
}
System.out.println("\nExiting Runnable's Run() that has value " + ch);
}
}
t1.start();
t2.start();