私は Java のスレッドをオンラインで学習していますが、私は初心者であり、いくつかの概念を理解するのに苦労しています。誰でも私を助けることができますか?
私が学んでいるリンク: http://www.codeproject.com/Articles/616109/Java-Thread-Tutorial
問題:
public class Core {
public static void main(String[] args) {
Runnable r0,r1;//pointers to a thread method
r0=new FirstIteration("Danial"); //init Runnable, and pass arg to thread 1
SecondIteration si=new SecondIteration();
si.setArg("Pedram");// pass arg to thread 2
r1=si; //<~~~ What is Happening here??
Thread t0,t1;
t0=new Thread(r0);
t1=new Thread(r1);
t0.start();
t1.start();
System.out.print("Threads started with args, nothing more!\n");
}
}
編集: FirstIteration と SceondIteration のコード
class FirstIteration implements Runnable{
public FirstIteration(String arg){
//input arg for this class, but in fact input arg for this thread.
this.arg=arg;
}
private String arg;
@Override
public void run() {
for(int i=0;i<20;i++){
System.out.print("Hello from 1st. thread, my name is "+
arg+"\n");//using the passed(arg) value
}
}
}
class SecondIteration implements Runnable{
public void setArg(String arg){//pass arg either by constructors or methods.
this.arg=arg;
}
String arg;
@Override
public void run() {
for(int i=0;i<20;i++){
System.out.print("2)my arg is="+arg+", "+i+"\n");
}
}
}