lr12 -> e1
This commit is contained in:
0
lr11/placeholder
Normal file
0
lr11/placeholder
Normal file
29
lr12/e1.java
Normal file
29
lr12/e1.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package lr12;
|
||||||
|
|
||||||
|
import java.time.LocalTime;
|
||||||
|
|
||||||
|
public class e1 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
Runnable task = () -> {
|
||||||
|
long endTime = System.currentTimeMillis() + 10_000;
|
||||||
|
|
||||||
|
while (System.currentTimeMillis() < endTime) {
|
||||||
|
System.out.println(
|
||||||
|
Thread.currentThread().getName() + " : " + LocalTime.now());
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Thread t1 = new Thread(task, "Thread-1");
|
||||||
|
Thread t2 = new Thread(task, "Thread-2");
|
||||||
|
|
||||||
|
t1.start();
|
||||||
|
t2.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user