メモ、備忘録、その他雑記を記載します。
ただし、このHPに記載している情報を利用した結果 損失・損害等が発生したとしても筆者は責任を持ちません。
Threadクラスから継承するスレッドと、Runnableインタフェースを持つスレッドの雛形です。
/**
* メインクラス
*
* @author
* @version 1.0
*/
public class Main {
/**
* アプリケーション起動処理
*
* @param args
* コマンドライン引数
* @return なし
*/
public static void main(String[] args) {
System.out.println("Hello");
ThreadClass tcs = new ThreadClass();
tcs.start();
ThreadIF tif = new ThreadIF();
Thread t = new Thread(tif);
t.start();
}
}
class ThreadClass extends Thread {
public void run() {
String str;
for (int i = 0; i < 10; i++) {
try {
sleep(100);
} catch (InterruptedException e) {
System.out.println(e);
}
str = String.format("class %04d", i);
System.out.println(str);
}
}
}
class ThreadIF implements Runnable {
public void run() {
String str;
for (int i = 0; i < 10; i++) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
System.out.println(e);
}
str = String.format("IF %04d", i);
System.out.println(str);
}
}
}
/**
* メインクラス
*
* @author
* @version 1.0
*/
public class Main {
/**
* アプリケーション起動処理
*
* @param args
* コマンドライン引数
* @return なし
*/
public static void main(String[] args) {
System.out.println("Hello");
ThreadClass tcs = new ThreadClass();
tcs.start();
ThreadIF tif = new ThreadIF();
Thread t = new Thread(tif);
t.start();
}
}
class ThreadClass extends Thread {
public void run() {
String str;
for (int i = 0; i < 10; i++) {
try {
sleep(100);
} catch (InterruptedException e) {
System.out.println(e);
}
str = String.format("class %04d", i);
System.out.println(str);
}
}
}
class ThreadIF implements Runnable {
public void run() {
String str;
for (int i = 0; i < 10; i++) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
System.out.println(e);
}
str = String.format("IF %04d", i);
System.out.println(str);
}
}
}
PR
コメントを書く