Does this mean that testThread and m_logTestThread are different instances but point to the same object in memory, so they are the same thread?
This is partly true. In fact, testThread and m_logTestThread are two different references not instances . And both links point to the same Thread object. So, just pointing reference m_logTestThread to null does not make the reference testThread also a reference to null .
You can also see this in practice with a simple example: -
String str = "abc"; String strCopy = str; // strCopy now points to "abc" str = null; // Nullify the `str` reference System.out.println(strCopy.length()); // Will print 3, as strCopy still points to "abc"
That way, even if you set one of the links to zero, the other link still points to the same Thread object. An object does not have the right to garbage collection until it points to 0 reference or circular reference .
See this link: Circular Link - The wiki page to find out exactly what Circular Refeference .
what is the purpose of "if (testThread! = null)"?
Simple You can infer from the condition that it checks if the testThread reference testThread to a null object. null check is done so that you do not get the NPE inside the if-construct , where you are trying to abort the Thread pointed to by this link. Therefore, if this link points to null , then you do not have a thread associated with this interrupt link.
source share