In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the types of Java thread states". The content of the explanation is simple and clear, and it is easy to learn and understand. let's go deep into the editor's train of thought. Let's study and learn "what are the types of Java thread states?"
Types of thread states
In the past, we were exposed to thread states: BLOCKED, WAITING, TIMED_WAITING, RUNABLE. Today, let's put it another way, what kind of thread will have this state.
In order to reduce the space, the basic concept of thread stack will not be repeated here. If you are interested, you can take a look at the previous article ThreadDump analysis.
1. Thread status is "waiting for monitor entry":
Meaning: it means that it is waiting to enter a critical section, so it is waiting in the "Entry Set" queue.
Current status: BLOCKED
For example: java.lang.Thread.State: BLOCKED (on object monitor)
Knowledge: note that "Entry Set" is the area where threads wait when we often use synchronized.
2, if a large number of threads are in "waiting for monitor entry":
Meaning: may be a global lock blocked a large number of threads, if the thread dump file printed many times in a short time reflects that with the passage of time, more and more threads of waiting for monitor entry, there is no decreasing trend, it may mean that some threads stay in the critical area for too long, so that more and more new threads can not enter the critical area.
Current status: BLOCKED
3. Thread status is "waiting on condition":
Meaning: it is waiting for another condition to occur to wake itself up, or it calls sleep (N).
Status: WAITING | | TIMED_WAITING
For example:
Java.lang.Thread.State: WAITING (parking): always waiting for a condition to happen
Java.lang.Thread.State: TIMED_WAITING (parking or sleeping): there is a timeout, and if that condition does not come, you will wake yourself up regularly.
4, if a large number of threads are in "waiting on condition":
Meaning: it may be that they go to get third-party resources, especially third-party network resources, and fail to get Response for a long time, resulting in a large number of threads entering a waiting state.
So if you find that there are a large number of threads in the Wait on condition, from the thread stack, waiting for the network to read and write *, this may be a sign of a network bottleneck, because the thread cannot execute because of network congestion.
Status: WAITING | | TIMED_WAITING
5. Thread status is "in Object.wait ()":
Meaning: after it gets the monitor (that is, starts executing the method of synchronized), it calls the java.lang.Object.wait () method.
At some point, each Monitor can only be owned by one thread, which is "Active Thread", while the other threads are "Waiting Thread", waiting in two queues "Entry Set" and "Wait Set" respectively. The state of the thread waiting in "Entry Set" is "Waiting for monitor entry", while the state of the thread waiting in "Wait Set" is "in Object.wait ()".
When the thread gets the Monitor, if it finds that the conditions for the thread to continue running are not met, it calls the wait () method of the object (usually the object being synchronized), abandons the Monitor and enters the "Wait Set" queue.
Status: TIMED_WAITING | | WAITING
For example:
Java.lang.Thread.State: TIMED_WAITING (on object monitor)
Java.lang.Thread.State: WAITING (on object monitor)
Knowledge points: generally, RMI-related threads (RMI RenewClean, GC Daemon, RMI Reaper), GC threads (Finalizer), reference object garbage collection threads (Reference Handler) and other system threads are in this state, as shown in the figure.
The above example
Just say it must be dry, let's take a look at a few samples to help you digest.
Round 1 status: waiting for monitor entry BLOCKED reason: this thread is waiting for the lock 0x00000000fe7exx61, waiting to enter the critical section: "RMI TCP Connection (12345)-xxx.52.xxx" daemon prio=10 tid=0x00000000405a6000 nid=0x68fe waiting for monitor entry [0x00007f2be65a3000] java.lang.Thread.State: BLOCKED (on object monitor) at com.xyz.goods.service.impl.GoodsServiceImpl.findChanellGoodsCountWithCache (GoodsServiceImpl.java:1734)-waiting to lock (a java.lang.String) so who currently holds the lock? Search the thread stack for 0x00000000fe7exx61 We will find that another thread called-locked to lock the scene "RMI TCP Connection (64878)-172.16.52.117" daemon prio=10 tid=0x0000000040822000 nid=0x6841 runnable [0x00007f2be76b3000] java.lang.Thread.State: RUNNABLEat java.net.SocketInputStream.socketRead0 (Native Method) at java.net.SocketInputStream.read (SocketInputStream.java:129) at java.io.BufferedInputStream.fill (BufferedInputStream.java:218) at java.io.BufferedInputStream.read1 (BufferedInputStream.java:258) at java.io. BufferedInputStream.read (BufferedInputStream.java:317)-locked (a java.io.BufferedInputStream) at org.bson.io.Bits.readFully (Bits.java:35) at org.bson.io.Bits.readFully (Bits.java:28) at com.mongodb.Response. (Response.java:35) at com.mongodb.DBPort.go (DBPort.java:110)-locked (a com.mongodb.DBPort) at com.mongodb.DBPort.go (DBPort.java:75)-locked (a com.mongodb.DBPort ) at com.mongodb.DBPort.call (DBPort.java:65) at com.mongodb.DBTCPConnector.call (DBTCPConnector.java:202) at com.mongodb.DBApiLayer$MyCollection.__find (DBApiLayer.java:296) at com.mongodb.DB.command (DB.java:152) at com.mongodb.DBCollection.getCount (DBCollection.java:760) at com.mongodb.DBCollection.getCount (DBCollection.java:731) at com.mongodb.DBCollection.count (DBCollection.java:697) at com.xyz.goods.manager.MongodbManager.count (MongodbManager.java:202) at com.xyz.goods.service.impl.GoodsServiceImpl.findChanellGoodsCount (GoodsServiceImpl.java:1787) at com.xyz.goods.service.impl.GoodsServiceImpl.findChanellGoodsCountWithCache (GoodsServiceImpl.java:1739)-locked (a java.lang.String) Round 2 status: waiting on condition [0x00007fd4f1a59000] TIMED_WAITING reason: wait for another condition to occur to wake yourself up: "RMI TCP Connection (idle)" daemon prio=10 tid=0x00007fd50834e800 nid=0x56b2 waiting on condition [0x00007fd4f1a59000] java.lang.Thread.State: TIMED_WAITING (parking) at sun.misc.Unsafe.park (Native Method)-parking to wait for (a java.util.concurrent.SynchronousQueue$TransferStack) at java.util.concurrent.locks.LockSupport.parkNanos (LockSupport.java:198) at java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill (SynchronousQueue.java:424) at java.util.concurrent.SynchronousQueue$TransferStack.transfer (SynchronousQueue.java:323) at java.util.concurrent.SynchronousQueue.poll (SynchronousQueue.java:874) at java.util.concurrent.ThreadPoolExecutor.getTask (ThreadPoolExecutor.java:945 ) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:907) at java.lang.Thread.run (Thread.java:662) 1) the timed_waiting in "TIMED_WAITING (parking)" refers to the waiting state But the time is specified here, and the waiting state is automatically exited when the specified time is reached. Parking means that the thread is suspended. 2) the state "waiting on condition" needs to be combined with the line "parking to wait for (a java.util.concurrent.SynchronousQueue$TransferStack)" in the stack. At this point, the thread must be waiting for a condition to happen to wake itself up. Secondly, SynchronousQueue is not a queue, but a mechanism for transferring information between threads. When we put an element into SynchronousQueue, another thread must be waiting for the task to be handed over, so this is the condition that this thread is waiting for, usually waiting for the task to appear. Round 3 status: TIMED_WAITING in Object.wait () reason: thread is actively suspended Waiting for a condition to wake up "RMI RenewClean- [172.16.50.182 java.lang.Thread.State 4888]" daemon prio=10 tid=0x0000000040d2c800 nid=0x97e in Object.wait () [0x00007f9ccafd0000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait (Native Method)-waiting on (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove (ReferenceQueue.java:118)-locked (a java.lang.ref.ReferenceQueue$Lock) at sun.rmi.transport.DGCClient$EndpointEntry$RenewCleanThread .run (DGCClient.java:516) at java.lang.Thread.run (Thread.java:662) Thank you for your reading The above is the content of "what are the types of java thread states". After the study of this article, I believe you have a deeper understanding of the types of Java thread states, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.