- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
class MoreThreads
{
public static void main(String[] args)
{
println("Запуск основного потока");
MyThread mt1 = new MyThread("Child #1");
MyThread mt2 = new MyThread("Child #2");
MyThread mt3 = new MyThread("Child #3");
MyThread mt4 = new MyThread("Child #4");
MyThread mt5 = new MyThread("Child #5");
MyThread mt6 = new MyThread("Child #6");
MyThread mt7 = new MyThread("Child #7");
MyThread mt8 = new MyThread("Child #8");
MyThread mt9 = new MyThread("Child #9");
MyThread mt10 = new MyThread("Child #10");
MyThread mt11 = new MyThread("Child #11");
MyThread mt12 = new MyThread("Child #12");
MyThread mt13 = new MyThread("Child #13");
MyThread mt14 = new MyThread("Child #14");
MyThread mt15 = new MyThread("Child #15");
MyThread mt16 = new MyThread("Child #16");
MyThread mt17 = new MyThread("Child #17");
MyThread mt18 = new MyThread("Child #18");
for(int i=0; i<50; i++) {
print(".");
try {
Thread.sleep(100);
}
catch(InterruptedException e) {
println("Прерывание основного потока");
}
}
println("Завершение основного потока");
}
static void print(String text)
{
System.out.print(text);
}
static void println(String text)
{
System.out.println(text);
}
}
class MyThread extends Thread
{
MyThread(String name) {
super(name);
setName(name);
start();
}
public void run() {
System.out.println(getName()+" - запуск");
try {
for(int count=0; count<10; count++) {
Thread.sleep(400);
System.out.println("В "+getName()+", счётчик: "+count);
}
}
catch(InterruptedException e) {
System.out.println(getName()+" прерван");
}
System.out.println(getName()+" - завершение");
}
}
Комментарии (0) RSS
Добавить комментарий