The Java™ Tutorils-Concerency:Pausing Execution with SleepはSleepでスレッドを停止して実行します。


The Java™ Tutorils-Concerency:Pausing Execution with SleepはSleepでスレッドを停止して実行します。
原文の住所:https://docs.oracle.com/javase/tutorial/essential/concurrency/sleep.html
肝心な点
sleepの時間は正確なではない。
スレッドの休止が中断されると、sleep方法はInterruptedException をスローします。
全文翻訳
Thread. sleep causes the current thread to suspend exection for a speciiifed period.Thisisisisaefficinentmeans of making processor time available to the the the the thethethe aaplication or or or thethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethetheaaaaaaaaaaaaaaaaaaaaaappppppplicininininininproproproproproproproproproproproproproproproproprotititititititititititiフォロワー、and waiting for another thread with duties that are undestood to have time requirements、as with the SimpleThexample in a later section.
Thread.sleepは、現在のスレッドが一時的にブロックされます。この有効な手段は同じプログラムの他のスレッドになります。あるいは他のプログラムはCPUに渡します。この方法は、以下の例のように、リズムを調整するためにも使用され得る。また、タスクを保持し、時間スライスが必要となる他のスレッドを待つためにも使用でき、後の授業のSimpleThreadの例に示すように。
Twowooverloaded versions of sleep are provided:one that speciiiifes the sleep time to the mimilisecond and one speciiies the sleeptime the naosecond.However,these ssleeptimes the at Alititititinininininininininininininininininininininininininininat thet thethetheaat thethethetheaaaattttttttttggggggggthethethethethethererereredededededededededededededededededededededededededededededebe terminated by interrupts、as we’ll see in later section.In any case,you cannot asume that invoking sleep will suspend the thread for precisely the time period specified.
Javaは、特定の休止時間を指定することができますが、単位はミリ秒で、単位はナノ秒です。しかし、これらのスリープ時間は、オペレーティングシステムによって提供される特性によって制限されるので、正確であるとは保証できない。また、休眠時間は中断によって決定され、次の章で見られます。いずれの場合も、スレッドをブロックするためにsleepを呼び出すと、指定されたスリープ時間まで正確に到達するとは仮定できない。
The SleepMessage s example uses sleep to print messages at four-second intervals:
このSleep Messageのサンプルは、Sleepを利用して、4秒ごとにメッセージを印刷する機能を実現する。
public class SleepMessages {
public static void main(String args[]) throws InterruptedException {
String importantInfo[] = {
"Mares eat oats",
"Does eat oats",
"Little lambs eat ivy",
"A kid will eat ivy too"
};

for (int i = 0;i < importantInfo.length; i++) {
//Pause for 4 seconds
Thread.sleep(4000);
//Print a message
System.out.println(importantInfo[i]);
}
}
}
Notice that mann declears that it throws InterruptedException.This is an exception that sleep throws when another thread interrupts the current thread while sleep is active.Since appis appination therept theretch
なお、main方法はInterruptedException異常を投げ出すことができると定義されている。他のスレッドが現在のスレッドの休止状態を中断すると、この異常をスローする。このウィジェットは定義されていないので、中断を引き起こす他のスレッドは、すべてこのInterruptedExceptionの異常をキャプチャする必要がありません。