Interrupt Brief Introduction
The interrupt () method simply changes the state of the interrupt, and it does not interrupt a running thread. What this method actually does is to send an interrupt signal to the blocked
In Java, is there a way to get the executing method to terminate execution?
For example: A method, I just want it to perform 10 minutes, more than 10 minutes, immediately stop execution. How much has been executed, and how much has not been performed, records its execution status.
Today, I will share a plan with you.
Over here:
1. Use the callable and future provided in JDK to help realize;
2, use the spring managed management
1. Introduction
When we click on the cancellation button of an antivirus software to stop the virus, when we typed the Quit command at the console to end a background service ... Requires a thread to cancel a task that another thread is performing. Java does not provide a safe and straightforward way to stop a thread,
methods throw interruptedexception, and when this exception is caught in the catch block, the thread's interrupt flag bit has been set to false. So call t.isinterrupted () in this catch block, thread.interrupted () is always false,
The difference between t.isinterrupted and thread.interrupted () is obvious in the API, thread.interrupted () If the current interrupt flag is true, the
The Java interrupt () method simply sets the interrupt token for the thread, when the interrupt method is invoked on a blocked thread (the blocked thread is the call to sleep, wait, jo
1. IntroductionWhen we click on the Cancel button of an antivirus to stop the virus, when we hit the QUIT command in the console to end a background service ... Requires one thread to cancel the task that another thread is performing. Java does not provide a safe and straightforward way to stop a thread, but
1. IntroductionWhen we click on the Cancel button of an antivirus to stop the virus, when we hit the QUIT command in the console to end a background service ... Requires one thread to cancel the task that another thread is performing. Java does not provide a safe and straightforward way to stop a thread, but
to handle this situation. Just like the hardware interruption of the CPU, the CPU is working. At this time, a peripheral tells the CPU that I have finished the work (or I interrupt you), and the CPU will put down the work in the hand, you can see what the problem is. You don't need to handle it yourself. Instead, you don't need to deal with the original job. If you need to handle it, you need to deal with the new job ~
The same is true for
is chosen from a multitude of executable states,In other words, the thread that is just now is still likely to be executed again, not necessarily the other line.The thread will not execute in the next time.There is a Thread.yield () method in the Java thread that many people translate into threading concessions. As th
The article is reproduced from the detailed analysis of the Java interrupt mechanism 1. IntroductionWhen we click on the Cancel button of an antivirus to stop the virus, when we hit the QUIT command in the console to end a background service ... Requires one thread to cancel the task that another thread is performing.
blocked state earlier. Very unlucky, there is no such a mechanism for all situations7 * applies, however, specific technologies can be used depending on the situation. Use Thread.Interrupt () to break the thread8 * The Thread.Interrupt () method does not break a running thread. This method9 * What is actually done is that a interrupt signal is thrown when the thread
In Java threads, the state of a thread is divided into 6 types. The official documentation is interpreted as:/*** Threadstateforathreadwhichhasnotyetstarted. */NEW, /*** threadstateforarunnablethread.athreadinthe Runnable*stateisexecutingin theJavavirtualmachinebutitmay *bewaitingforotherresourcesfromtheoperating system*suchasprocessor. */runnable, /***threadstatefora threadblockedwaitingforamonitorlock. *a
If a Java program has more than one thread of execution, the Java program can run to the end when all the threads are running, or, more precisely, when all non-daemon threads run at the end, or when one of the threads calls the System.exit () method. This Java program will run to the end.Java provides an
There are two sections of code:
Code 1:
// Thread interruption operation (1)
Code 2:
// Thread interrupt operation (2) the thread is not interrupted, and interrupt can only interrupt sleep, wait and other methods
We can see fr
Go from: http://polaris.blog.51cto.com/1146394/372146
in Java, you used the Stop method to stop a thread, however, the method is inherently unsafe and thus has been discarded (deprecated). So how should we end a process? This is explained in detail in the official document: "Why is it not in favour of using Thread.stop, Thread.Suspend and Thread.Resume?" 》。 Description of the Stop method is referenced
Use the thread's Abort method to terminate the thread, while the thread's interrupt method can only break the thread in the WaitSleepJoin state, and the thread resumes execution when the thread state is no longer waitsleepjoin. Calling the Abort method on a
interrupt identifier bit(2) The 6th line of the second part is the prototype of the Interrupt0 () method, because the method is native modified, it is obvious that this is a local method, is implemented by the Java Virtual machine2, isinterrupted ()The only function of the method is to test whether the thread has been interrupted, the state of the
control the order in which multiple threads run, thus reproducing the deadlock scene. Since GDB can be used to drive debugging with a Python script, it is theoretically possible to test the program automatically in a different thread run order.
Therefore, the Non-stop mode is naturally a multi-threaded debugging "must kill skill". The Linux version released after the second half of 2009 years has a GDBv7.0 version. Very curious, do not know whe
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.