我正在尝试从我正在创建的线程中使用的类的run()方法中进行线程休眠,从而在调用时让线程处于休眠状态,并且我从eclipse接收和错误.目标只是多次测试代码并看到线程在不同时间输出,因为我知道选择要运行的线程并不是决定性的事情.
我的代码如下
package multithreading;
public class Mainclass {
public static void main(String[] args) {
run work= new run();
Thread thread = new Thread(work);
thread.start();
System.out.println("main thread is running");
}// end of main
}// end of class mainclass
Run Code Online (Sandbox Code Playgroud)
这里是我在上面创建一个实例/对象的运行类
public class Run implements Runnable{// this is the beggining of the class
public void run(){
try {
thread.sleep(200);
}catch (InterruptedException ex) {
}
System.out.println("the second thread is running");
}// end of run method of the class run
}// end of class run
Run Code Online (Sandbox Code Playgroud)
任何帮助都会有很大的帮助
| 归档时间: |
|
| 查看次数: |
2999 次 |
| 最近记录: |