3

Java threaded interrupt extinction - codesd.com

 2 years ago
source link: https://www.codesd.com/item/java-threaded-interrupt-extinction.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Java threaded interrupt extinction

advertisements

Here Is my program that produces an InterruptedException.

timepass.java

 public class timePass {
    private static void book() {
        System.out.print("book");
    }
    public static void main(String args[]){
            Thread.sleep(1);
            book();
      }
    }

I would like to know the reason for the thrown exception.


put code in try catch block

 try
  {
  Thread.sleep(1);
  book();
  }
  catch(InterruptedException e)
  {
   System.out.println("Error message");
  }

Related Articles

Java Thread interrupt: interrupt () vs stop ()

I have a problem when working with thread in Java. What is the method preferred between interrupt() and stop() for interrupting a thread in Java? And why? Thanks for any responses.Theoretically, with the manner you posed the question, neither of them

Java - thread interruption?

I got a question about interrupting threads in Java. Say I have a Runnable: public MyRunnable implements Runnable { public void run() { operationOne(); operationTwo(); operationThree(); } } I want to implement something like this: Thread t = new Thre

Thread.interrupt () and java.io.InterruptedIOException

I'm running Java 1.5 on Solaris 10. My program is a standalone java program, using java concurrency package and log4j-1.2.12.jar to log certain information. primary logic is as below ExecutorService executor = new AppThreadPoolExecutor(10, 10, 0L, Ti

Stopping or interrupting a Java thread

I am trying to stop a java thread if it is running for 6000 milliseconds. Below code to kill the Thread R1 is failed to stop the thread. could you please correct code? I have tried this code with while (!Thread.currentThread().isInterrupted()) to sto

Thread interruption in Java

I have a situation where I'm using a Thread, she call a method that will do multiple processes, I need to use a "cancel" button in which you have to stop the thread, I not can use: "while" ,to verify that it was canceled because it not

Thread Interrupt in Java

I have the following questions, if I interrupt a thread in java, a process that is running 15 minutes, it will stop the process, stop the methods or will finish this process,and not allow others continue in line? I have a "thread" that will call

How do I catch an interrupted exception in a Java thread?

Ok, in one of my classes i want to throw an InterruptedException. I do that by calling thread.interrupt(); As far as I know this will throw an InterruptedException. What I would like to know is how I can catch this exception in my thread. This obviou

Any techniques to interrupt, kill or otherwise (releasing synchronization locks) a single Java thread blocked by deadlock allowing other threads to continue?

I have a long-running process where, due to a bug, a trivial/expendable thread is deadlocked with a thread which I would like to continue, so that it can perform some final reporting that would be hard to reproduce in another way. Of course, fixing t

Java threads common issues

I have some questions about java threads: if I have a class that runs a number of threads when one thread reaches to exit(1) command line will it exit the thread or the whole application including the other threads? 2.how can I make one thread notify

How to Debug Java Thread in WAITING State

I am trying to test spark 1.6 with NFS connector and submitted the job with spark-submit, the job completes successfully and its prints the results on the console as well. The web-UI also says it's completed. However, the spark-submit never terminate

When a Java thread performs a potentially blocking action, does it always lose the current processor time?

A potentially blocking action (e.g. Thread.join(), obj.wait(), monitorEnter ), may continue to execute under some circumstances (e.g. For Thread.join(), if the interrupt flag is set by the time of calling, the method won't block. For obj.wait(), if t

How do I understand Thread.interrupt ()?

There are two code block in java. Block One: @Test public void test1() { System.out.println("interrupt:" + Thread.currentThread().isInterrupted()); Thread.currentThread().interrupt(); System.out.println("interrupt:" + Thread.currentThr

Why can not Thread.interrupt () interrupt a thread trying to acquire a lock

In the book Thinking in Java it is written that Thread.interrupt() cannot interrupt a thread which is trying to acquire a synchronized lock, I want to know why?A blocking operation can be interrupted only if it is declared to throw InterruptedExcepti

to kill a java thread in the test

I'm writing a sort of tutorial about programming (it will be a Java repo on github) where users can clone the repo and write their own code inside empty methods to solve algorithmic problems. After they write their code, they can launch unit tests to

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK