완전한 참고서를 사용하여 Java를 배우고 있습니다. 저는 지금 Multithreded Programming Concept에 있습니다. 이 프로그램의 실행 단계를 이해하는 데 도움을주십시오.프로그램 이해를위한 도움이 필요합니다.
// This program is not synchronized.
class Callme {
void call(String msg) {
System.out.print("[" + msg);
try {
Thread.sleep(1000);
} catch(InterruptedException e) {
System.out.println("Interrupted");
}
System.out.println("]");
}
}
class Caller implements Runnable {
String msg;
Callme target;
Thread t;
public Caller(Callme targ, String s) {
target = targ;
msg = s;
t = new Thread(this);
t.start();
}
public void run() {
target.call(msg);
}
}
class Synch {
public static void main(String args[]) {
Callme target = new Callme();
Caller ob1 = new Caller(target, "Hello");
Caller ob2 = new Caller(target, "Synchronized");
Caller ob3 = new Caller(target, "World");
// wait for threads to end
try {
ob1.t.join();
ob2.t.join();
ob3.t.join();
} catch(InterruptedException e) {
System.out.println("Interrupted");
}
}
}
논리를 이해할 수 없습니다.
@HighCore 님이 귀하의 의견을 이해할 수 없었습니다. – user3203399
@HighCore Java는 동기화/대기 설정도 지원하지만 선택하면 Runnable 클래스를 서브 클래스화할 수도 있습니다. 어쨌든 일반적으로 Java에서는 동기화/대기를 사용하거나 데이터를 저장하는 경우 휘발성 변수 유형을 사용할 수 있습니다. –
@dylanlawrence ** ['async/await'] (http://msdn.microsoft.com/en-us/library/hh191443.aspx)/계속 ** 언어 수준 ** 지원의 아름다움에 가까운 아무 데나 ** C#에서. –