public static void Main (string[] args) {
Runner1 r1 = new Runner1 ();
Thread t = new thread (r1);
T.start ();
for (int i = 0; i <; i++) {
System.out.println ("mainthread-->" +i);
}
}
Runner1 Implementing the Runable interface
Class Runner1 implements runnable{
@Override
public void Run () {
for (int i = 0; i < i++) {
System.out.println ("runner1-->" +i);
}
}
}
Program Run Result:
Runner1-->0
Mainthread-->0
Mainthread-->1
Mainthread-->2
Mainthread-->3
Mainthread-->4
Mainthread-->5
Runner1-->1
Mainthread-->6
Runner1-->2
Mainthread-->7
Runner1-->3
Mainthread-->8
Mainthread-->9
Mainthread-->10
Mainthread-->11
Mainthread-->12
Mainthread-->13
Mainthread-->14
Mainthread-->15
Mainthread-->16
Mainthread-->17
Mainthread-->18
Mainthread-->19
Runner1-->4
Mainthread-->20
Runner1-->5
Mainthread-->21
Mainthread-->22
Mainthread-->23
Mainthread-->24
Runner1-->6
Mainthread-->25
Runner1-->7
Mainthread-->26
Runner1-->8
Runner1-->9
Runner1-->10
Runner1-->11
Runner1-->12
Runner1-->13
Runner1-->14
Runner1-->15
Runner1-->16
Mainthread-->27
Runner1-->17
Runner1-->18
Runner1-->19
Runner1-->20
Runner1-->21
Runner1-->22
Runner1-->23
Runner1-->24
Runner1-->25
Runner1-->26
Mainthread-->28
Runner1-->27
Mainthread-->29
Runner1-->28
Mainthread-->30
Runner1-->29
Runner1-->30
Runner1-->31
Runner1-->32
Runner1-->33
Runner1-->34
Runner1-->35
Runner1-->36
Runner1-->37
Mainthread-->31
Mainthread-->32
Mainthread-->33
Mainthread-->34
Mainthread-->35
Mainthread-->36
Mainthread-->37
mainthread-->38
mainthread-->39
Mainthread-->40
mainthread-->41
Mainthread-->42
mainthread-->43
Mainthread-->44
Mainthread-->45
mainthread-->46
mainthread-->47
mainthread-->48
mainthread-->49
Mainthread-->50
Mainthread-->51
mainthread-->52
mainthread-->53
mainthread-->54
Mainthread-->55
mainthread-->56
mainthread-->57
mainthread-->58
mainthread-->59
Mainthread-->60
mainthread-->61
mainthread-->62
mainthread-->63
Mainthread-->64
Mainthread-->65
mainthread-->66
mainthread-->67
mainthread-->68
mainthread-->69
Mainthread-->70
mainthread-->71
mainthread-->72
mainthread-->73
mainthread-->74
Mainthread-->75
mainthread-->76
Mainthread-->77
mainthread-->78
mainthread-->79
Mainthread-->80
mainthread-->81
mainthread-->82
mainthread-->83
mainthread-->84
Mainthread-->85
Mainthread-->86
mainthread-->87
mainthread-->88
mainthread-->89
Mainthread-->90
mainthread-->91
mainthread-->92
mainthread-->93
mainthread-->94
Mainthread-->95
mainthread-->96
mainthread-->97
Mainthread-->98
mainthread-->99
runner1-->38
runner1-->39
Runner1-->40
runner1-->41
Runner1-->42
runner1-->43
Runner1-->44
Runner1-->45
runner1-->46
runner1-->47
runner1-->48
runner1-->49
The difference between the normal method and the common approach: the thread execution body and the main course split time slice run
Java Thread 1