![]() If you can recall, the stack trace of the ResourceDataOne thread indicated a problem while executing the code around line number 68 (see Figure 4) of the ResourceMonitor.java file. Let us therefore open the ResourceMonitor.java file.įigure 6 : The lines of code executed by the ResourceDataOne thread We now need to examine the code in this file to figure out why the deadlock occurred. With that, we can conclude that both threads are blocking each other, thus making for an ideal deadlock situation.Īnalysis of the stack trace of the ResourceDataTwo thread (see Figure 5) reveals that once started, the thread executed line 94 of the ResourceMonitor.java file, which in turn invoked line 21 of the same file since no lines of code have been executed subsequently, we can conclude that the deadlock occurred at line 21 only.įigure 5 : The stack trace for the ResourceDataTwo threadįrom the above discussion, we can infer both the threads deadlocked while attempting to execute code contained within the ResourceMonitor.java file. As you can see in Figure 5, the Thread State clearly indicates that the ResouceDataTwo thread has been blocked by the ResourceDataOne thread. ![]() To view the stack trace of this thread, click on the thread name in the left panel of Figure 4. Let us now shift our focus to the ResourceDataTwo thread. If you closely scrutinize the stack trace of ResourceDataOne, you will uncover that once the thread started running, it executed line 40 of the ResourceMonitor.java program file, which in turn invoked line 68 of the same file the deadlock appears to have occurred at line 68 only. From the Thread State, it is evident that the ResourceDataOne thread has been blocked on an object that is owned by the ResourceDataTwo thread. For this default selection, the contents of the right panel will be as depicted by Figure 4 above. The left panel of Figure 4 lists the 2 deadlocked threads, with the thread that is the leading CPU consumer being selected by default – in the case of our example, this is the ResourceDataOne thread. Figure 4 will then appear.įigure 4 : The stack trace for the ResourceDataOne thread To keenly focus on the stack trace, without being distracted by the other columns in Figure 2 and Figure 3, click on the icon in Figure 2. For this purpose, scroll to the left of Figure 2 to view the stack trace clearly (see Figure 3)įigure 3 : Viewing the stack trace of the deadlocked threads To figure out why these two threads are deadlocked, you would have to carefully review the stack trace of both these threads. Figure 2 then appears.įigure 2 : The detailed diagnosis page revealing the deadlocked threadsįigure 2 clearly reveals that 2 threads, namely – the ResourceDataTwo and the ResourceDataOne thread - are in a deadlock currently. To know which threads are in a deadlock, click on the 'magnifying glass' icon corresponding to the Deadlock threads measure. When, say 2 threads are deadlocked for a particular resource/object, then the Deadlock threads measure will report the value 2, as depicted by Figure 1.įigure 1 : The JVM Threads test reporting 2 Deadlock threads Until a deadlock situation arises, the Deadlock threads measure reported by the JVM Threads test will report only 0 as its value. In this section, the aws02_japp application is used one more time to explain how the eG JVM Monitor can be used to report on deadlock situations in your JVM, and to diagnose the root-cause of the deadlock. and Diagnosing a Thread Deadlock Situation in the JVM New Thread (new InterThreadDemo ()).start () Public static void main (String args) throws Exception Public class InterThreadDemo implements Runnable ![]() notifyAll () : Wakes up all threads waiting on the object monitor.Įxample : Sample program to implement inter thread communication notify () : Wakes up the single thread waiting on the object monitor.ģ. Public final void wait (long timeout) InterruptedExceptionĢ. Public final void wait () throws InterruptedException, wait (): It causes the current thread to wait until another thread invokes the notify ( ) or notifyAll( ) method. Three methods used for thread communication are:ġ. Inter thread communication helps in avoiding thread pooling. } Inter Thread CommunicationInter thread communication is used when an application has two or more threads that exchange same information. ![]() Example : Program to exhibit deadlock in Java
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |