Reference Link: 8288251Reentrantlock Class 1.1 What is the lock framework in Reentrantlock Java.util.concurrent.lock is an abstraction of locking, which allows the implementation of a lock to be implemented as a Java class, rather than as a language feature. This leaves space for the various implementations of lock, which may have different scheduling algorithms, performance characteristics, or locking semantics. The Reentrantlock class implements loc
Use of Java concurrent programming thread pool (3)Thread factory
Every time the thread pool needs to create a thread, it is completed through the thread factory method. The default thread
1, the thread status is "Waiting for monitor entry":means that itwaiting to enter a critical section, so it waits in the "Entry Set" queue. At this point the thread state is generally Blocked:
Java.lang.Thread.State: BLOCKED (on object monitor)
2, the thread status is "Waiting on condition":Explain itwaiting for another condition to happen, to wake
1.Jstack Usage IntroductionThis command prints a stack trace of the Java thread, knowing which threads are blocked or waiting to find reasons such as thread deadlockUsage:Common options:-F 当’jstack [-l] pid’没有相应的时候强制打印栈信息-l 长列表. 打印关于锁的附加信息,例如属于java.util.concurrent的ownable synchronizers列表.-m 打印java和native
Thread FactoryEach time a thread pool needs to create a thread, it is perfected by the thread factory method. The default thread factory method creates a new, non-daemon thread and does not contain special configuration informatio
Today, in the online Java code, I handled a problem caused by the ExecutorServicec thread pool and precipitated the processing process and some debugging.
Scenario Description
In the distributed task processing module, there is a Java daemon process that receives the Java code description task (jar) through the queue
, such as writing a dead recursion, it is possible to cause this situation. Let's use a piece of code to simulate a memory overflow in this case.import java.util.*; import java.lang.*; public class OOMTest{ public void stackOverFlowMethod(){ stackOverFlowMethod(); } public static void main(String... args){ OOMTest oom = new OOMTest(); oom.stackOverFlowMethod(); } } Running the above code will throw the following exception:
Troubleshooting of java thread Blocking
The worker I developed is blocked once every several months and has never been checked for any problems. Today, I finally got this knot. Summarize the solution process and share it with you.
First, run the jstack command to display all the thread stacks of the process. After obtaining the
If it is impossible to avoid nesting requests for Lock resources, you need to develop a strategy for requesting lock resources, first plan which locks are available, and then each thread requests them in one order, do not show the order in the above example, so there will be potential deadlock Problems
3) Try timed lock
Java 5 provides more flexible lock tools to explicitly request and release locks. You c
Here is a summary of the search steps for the thread resource footprint of the Linux, Sun (Oracle) JDK; In a Linux environment, when the Java process is found to be high in CPU resources and want to further identify which Java thread is consuming CPU resources, Follow these steps to find:
(a): see what threads of
The first step is to find out the Java process PID: Grep-v "awk ' {print $2} ' The second step is to find the most CPU -Consuming threads : PS-MP pid-o Thread,tid,sort-rn-k9The third step is to convert the TID to a three- input system : printf "%x\n" tidThe fourth step is to dump the JVM stack information : Jstack PIDthe NID in jstack corresponds to the
Test thread deadlock, run the following code:
public class Test1 {
private static Object O1 = new Object ();
private static Object O2 = new Object ();
public static void Main (string[] args) {for
(int i = 0;ipublic void Run () {
synchronized (O1) {
synchronized (O2) {
System.out.println ("AM O1");
}
}
}). Start ();
New Thread (New Runnable () {
@Override public
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.