简体   繁体   English

Interruptedexception 的不间断捕获块

[英]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.

相关问题 InterruptedException没有捕获? - InterruptedException not catch? 如果在线程的InterruptedException的catch块中使用“返回”,该返回哪里? - Where does “return” returns if used inside the catch block of an InterruptedException in a thread? 在哪里使用synchronized块捕获Object.wait()的InterruptedException? - Where to catch InterruptedException for Object.wait() with synchronized block? Java:当在 catch 块中抛出 InterruptedException 时,finally-block 似乎被执行了两次 - Java: finally-block seems to be executed twice when InterruptedException is thrown in catch block Java 线程 InterruptedException 块未执行 - Java thread InterruptedException block not executing 在InterruptedException的catch子句中中断线程的原因是什么? - What is the reason for interrupting the thread in the catch clause of InterruptedException? 捕获InterruptedException时JVM是否需要退出 - Does JVM need to exit when catch InterruptedException 为什么要捕获InterruptedException来调用Thread.currentThread.interrupt()? - Why would you catch InterruptedException to call Thread.currentThread.interrupt()? 无法访问的捕获块:InvalidFormatException的无法访问的捕获块 - Unreachable catch block: Unreachable catch block for InvalidFormatException 无法到达的渔获量问题 - Unreacheable Catch Block Issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM