私はJAVAのスレッドの概念にまったく慣れていません。いくつかのコードを試してみましたが、それらは機能していますが、バックグラウンドで何が起こっているのか正確にはわかりません. たとえば、次のコードを書きました。
public class myThreadTest implements Runnable {
private static void ping(String text, int count)
throws InterruptedException {
for (int i = 0; i<count; i++) {
System.out.println("ping "+text+i+"...");
Thread.sleep(1000);
}
}
public void run() {
try {
ping("run ",10);
} catch (InterruptedException e) {
}
}
public static void main(String[] args) {
(new Thread(new myThreadTest())).start();
try {
ping("main ", 5);
} catch (InterruptedException e) {
}
}
}
ここで実行されている2つのスレッドがあり、1つはメインから実行され、もう1つはメソッド実行から実行されていますか? 私が得る出力は、main、run、main、run、run、main ...のようなものです。