編集の要約なし |
|||
(同じ利用者による、間の4版が非表示) | |||
1行目: | 1行目: | ||
([[java.lang | ([[java.lang のクラスたち|java.lang]].)Thread [https://docs.oracle.com/javase/jp/8/docs/api/java/lang/Thread.html] | ||
私はスレッドを制御します。JVMでは、アプリケーションは並列に実行される複数のスレッドを使用することができます。 | 私はスレッドを制御します。JVMでは、アプリケーションは並列に実行される複数のスレッドを使用することができます。 | ||
== | ==フィールド== | ||
* public static final int MIN_PRIORITY - スレッドに設定できる最低優先順位 | * public static final int MIN_PRIORITY - スレッドに設定できる最低優先順位 | ||
* public static final int NORM_PRIORITY - スレッドに割り当てられるデフォルトの優先順位 | * public static final int NORM_PRIORITY - スレッドに割り当てられるデフォルトの優先順位 | ||
* public static final int MAX_PRIORITY - スレッドに設定できる最高優先順位 | * public static final int MAX_PRIORITY - スレッドに設定できる最高優先順位 | ||
== | ==メソッド== | ||
* | * sleep* - 現在実行中のスレッドを指定されたミリ秒数の間スリープ(一時的に停止)させる | ||
==例== | |||
現在実行中のスレッドを指定されたミリ秒数の間スリープ(一時的に停止)させます。 | |||
String str = "Hello World!!\nAre you enjoying Java?"; | |||
char[] chars = str.toCharArray(); | |||
for (char letter : chars) { | |||
System.out.print(letter); | |||
try { | |||
Thread.sleep(100); | |||
} catch (InterruptedException e) { | |||
System.out.println("error!"); | |||
} | |||
} | |||
System.out.println(""); |
2019年6月28日 (金) 20:44時点における最新版
私はスレッドを制御します。JVMでは、アプリケーションは並列に実行される複数のスレッドを使用することができます。
フィールド
- public static final int MIN_PRIORITY - スレッドに設定できる最低優先順位
- public static final int NORM_PRIORITY - スレッドに割り当てられるデフォルトの優先順位
- public static final int MAX_PRIORITY - スレッドに設定できる最高優先順位
メソッド
- sleep* - 現在実行中のスレッドを指定されたミリ秒数の間スリープ(一時的に停止)させる
例
現在実行中のスレッドを指定されたミリ秒数の間スリープ(一時的に停止)させます。
String str = "Hello World!!\nAre you enjoying Java?"; char[] chars = str.toCharArray(); for (char letter : chars) { System.out.print(letter); try { Thread.sleep(100); } catch (InterruptedException e) { System.out.println("error!"); } } System.out.println("");