Когда поток спит в следующем коде? - PullRequest
0 голосов
/ 16 декабря 2018
1- package demotest;
2- public class thread_example1 implements Runnable {
3- @Override
4- public void run() {
5- }
6- public static void main(String[] args) {
7-     Thread guruthread1 = new Thread();
8-     guruthread1.start();
9-     try {
10-         guruthread1.sleep(1000);
11-     }   catch (InterruptedException e) {
12-     // TODO Auto-generated catch block
13-         e.printStackTrace();
14-     }
15-     guruthread1.setPriority(1);
16-     int gurupriority = guruthread1.getPriority();
17-     System.out.println(gurupriority);
18-     System.out.println("Thread Running");
19-     Process proc = rt.exec("mspaint");
20-     Thread.sleep(5000);
21-     proc.destroy();
22- }
23- } 

В чем разница между строкой 7 и строкой 20?есть ли в обеих ситуациях нить приостановится?Они выполняют ту же задачу, что и я?

I have this schedule :
Operation                          Line Number
Execution Paused                   10 and 20
Start Execution                    8
Closing Child Process              21
Thread Creation                    7
Execution of Child Process         19
Adjusting Priority                 15
Reading Priority                   16

Есть еще строки?например, при выполнении паузы у нас есть 2 строки.Другие операции также имеют более одной строки?

Кроме того, мои ответы верны.

1 Ответ

0 голосов
/ 16 декабря 2018

guruthread1.sleep () и Thread.sleep () делают здесь то же самое - они приостанавливают основной поток.guruthread1.sleep () - вводящий в заблуждение вызов, так как sleep () - статический метод класса Thread

...