[英]Uninterrupted catch block for Interruptedexception
I have written the following java code for runnable approach for creating new thread and getting errors as given below after the codes.我已经为可运行的方法编写了以下 java 代码,用于创建新线程并在代码后获取如下错误。 If anyone can help me sort out this thing would be appreciated.如果有人能帮我解决这个问题,我将不胜感激。
The errors are as follows:错误如下:
You have to pay attention to the upper and lower case of the class names.您必须注意类名的大小写。 That way, "thread" becomes "thread."这样,“线程”就变成了“线程”。 Also use thread#currentthread, not thread#currentthread, this method does not exist.同样使用thread#currentthread,而不是thread#currentthread,这个方法不存在。 The same goes for thread#sleep and the constructor. thread#sleep 和构造函数也是如此。
Example:例子:
public final class ThreadDemo implements Runnable {
@Override
public void run() {
Thread currentThread = Thread.currentThread();
Thread executingThread = new Thread(this, "Demo-Thread");
executingThread.start();
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
Also it is not possible to have a method 2 times in one class.同样,一个方法不可能在一个班级中出现 2 次。 So remove a run method.所以删除一个 run 方法。 Also, next time I ask you to use the codeblock and no images.另外,下次我要求您使用代码块而不使用图像时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.