File: /var/www/html/unitime/Documentation/Scripts/Thread Dump.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script PUBLIC "-//UniTime//DTD University Course Timetabling/EN" "http://www.unitime.org/interface/Script.dtd">
<!--
* Licensed to The Apereo Foundation under one or more contributor license
* agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*
* The Apereo Foundation licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
-->
<script name="Thread Dump" permission="Script Edit" engine="ECMAScript" created="Wed Mar 02 16:27:46 EST 2016">
<description><![CDATA[Generate thread dump]]></description>
<body><![CDATA[var dump = java.lang.management.ManagementFactory.getThreadMXBean().dumpAllThreads(true, true)
var file = log.createOutput('dump', 'txt');
var out = new java.io.PrintWriter(new java.io.FileWriter(file));
for (var i = 0; i < dump.length; i++) {
if (i > 0) out.println();
var d = dump[i];
out.print("\"" + d.getThreadName() + "\" Id=" + d.getThreadId() + " " + d.getThreadState());
if (d.getLockName() != null) out.print(" on " + d.getLockName());
if (d.getLockOwnerName() != null)
out.print(" owned by \"" + d.getLockOwnerName() + "\" Id=" + d.getLockOwnerId());
if (d.isSuspended()) out.print(" (suspended)");
if (d.isInNative()) out.print(" (in native)");
out.println();
var j = 0;
for (; j < d.getStackTrace().length; j++) {
var ste = d.getStackTrace()[j];
out.println("\tat " + ste);
if (j == 0 && d.getLockInfo() != null) {
if (d.getThreadState() == java.lang.Thread.State.BLOCKED)
out.println("\t- blocked on " + d.getLockInfo());
else if (d.getThreadState() == java.lang.Thread.State.WAITING || d.getThreadState() == java.lang.Thread.State.TIMED_WAITING)
out.println("\t- waiting on " + d.getLockInfo());
}
for (var k = 0; k < d.getLockedMonitors().length; k++) {
if (d.getLockedMonitors()[k].getLockedStackDepth() == j)
out.println("\t- locked " + d.getLockedMonitors()[k]);
}
}
if (j < d.getStackTrace().length) out.println("\t...");
if (d.getLockedSynchronizers().length > 0) {
out.println();
out.println("\tNumber of locked synchronizers = " + d.getLockedSynchronizers().length);
for (var k = 0; k < d.getLockedSynchronizers().length; k++) {
out.println("\t- " + d.getLockedSynchronizers()[k]);
}
}
}
out.flush(); out.close();]]></body>
</script>