Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to uniquely identify the instance of a class loader in Java
    primarykey
    data
    text
    <p>I have a problem which looks like it is being caused because two instances of a classloader are being used at the same time. A scheduled task is always being run twice instead of once, even with settings to avoid concurrent usage. </p> <p>How can I uniquely identify the Class loader instance for a given class instance at runtime? I know its fully qualified name would be a combination of classloader, package, and class name. I want to know if two individual instances of the same class loader are running concurrently. </p> <p>I tried logging, using the following, but it gave me nothing useful in terms of what I was actually hoping to see (something equivalent to a unique thread id etc). yes, it does give the type of classloader and its parent name but this is insufficient to assist me with the issue.</p> <pre><code>final String classLoaderInfoCurrentThread = Thread.currentThread().getContextClassLoader().toString(); final String classLoaderInfoClass = getClass().getClassLoader().toString(); logger.debug("Class loader info current thread: " + classLoaderInfoClass); logger.debug("Class loader info class: " + classLoaderInfoCurrentThread); </code></pre> <p>Results of above:</p> <p>Class loader info class: WebappClassLoader</p> <p>context: </p> <p>delegate: false</p> <p>repositories: /WEB-INF/classes/</p> <p>----------> Parent Classloader: org.apache.catalina.loader.StandardClassLoader@68de123</p> <p>Any ideas much appreciated.</p> <p>UPDATE:</p> <p>Thanks for quick feedback. Using the system hashcode was sufficient to confirm same classloader. The hash on StandardClassLoader was also useful in retrospect as helpfully pointed out in comments. I ran check on thread ids which are different. </p> <p>Using Spring with Tomcat, and Quartz 1.8 scheduling framework. </p> <p>By raising the logging on Spring / Quartz, I am able to identify that two different scheduler instances are being started up:</p> <pre><code>org.quartz.core.QuartzScheduler - Scheduler meta-data: Quartz Scheduler (v1.8.6) 'scheduler' with instanceId '&lt;compname&gt;.local1375104695468' org.quartz.core.QuartzScheduler - Scheduler meta-data: Quartz Scheduler (v1.8.6) 'scheduler' with instanceId '&lt;compname&gt;.local1375104696411' </code></pre> <p>It appears there is a known issue with this:</p> <p><a href="https://stackoverflow.com/questions/7223108/quartz-job-runs-twice-when-deployed-on-tomcat-6-ubuntu-10-04lts">Quartz job runs twice when deployed on tomcat 6/Ubuntu 10.04LTS</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload