src/java.management/share/classes/java/lang/management/ThreadInfo.java

Print this page
rev 10521 : 8055723[core]: Replace concat String to append in StringBuilder parameters
Contributed-by: Otavio Santana <otaviojava@java.net>


 562      *
 563      * @return <tt>true</tt> if the thread is executing native code;
 564      *         <tt>false</tt> otherwise.
 565      */
 566     public boolean isInNative() {
 567          return inNative;
 568     }
 569 
 570     /**
 571      * Returns a string representation of this thread info.
 572      * The format of this string depends on the implementation.
 573      * The returned string will typically include
 574      * the {@linkplain #getThreadName thread name},
 575      * the {@linkplain #getThreadId thread ID},
 576      * its {@linkplain #getThreadState state},
 577      * and a {@linkplain #getStackTrace stack trace} if any.
 578      *
 579      * @return a string representation of this thread info.
 580      */
 581     public String toString() {
 582         StringBuilder sb = new StringBuilder("\"" + getThreadName() + "\"" +
 583                                              " Id=" + getThreadId() + " " +
 584                                              getThreadState());


 585         if (getLockName() != null) {
 586             sb.append(" on " + getLockName());
 587         }
 588         if (getLockOwnerName() != null) {
 589             sb.append(" owned by \"" + getLockOwnerName() +
 590                       "\" Id=" + getLockOwnerId());
 591         }
 592         if (isSuspended()) {
 593             sb.append(" (suspended)");
 594         }
 595         if (isInNative()) {
 596             sb.append(" (in native)");
 597         }
 598         sb.append('\n');
 599         int i = 0;
 600         for (; i < stackTrace.length && i < MAX_FRAMES; i++) {
 601             StackTraceElement ste = stackTrace[i];
 602             sb.append("\tat " + ste.toString());
 603             sb.append('\n');
 604             if (i == 0 && getLockInfo() != null) {
 605                 Thread.State ts = getThreadState();
 606                 switch (ts) {
 607                     case BLOCKED:
 608                         sb.append("\t-  blocked on " + getLockInfo());
 609                         sb.append('\n');
 610                         break;
 611                     case WAITING:
 612                         sb.append("\t-  waiting on " + getLockInfo());
 613                         sb.append('\n');
 614                         break;
 615                     case TIMED_WAITING:
 616                         sb.append("\t-  waiting on " + getLockInfo());
 617                         sb.append('\n');
 618                         break;
 619                     default:
 620                 }
 621             }
 622 
 623             for (MonitorInfo mi : lockedMonitors) {
 624                 if (mi.getLockedStackDepth() == i) {
 625                     sb.append("\t-  locked " + mi);
 626                     sb.append('\n');
 627                 }
 628             }
 629        }
 630        if (i < stackTrace.length) {
 631            sb.append("\t...");
 632            sb.append('\n');
 633        }
 634 
 635        LockInfo[] locks = getLockedSynchronizers();
 636        if (locks.length > 0) {
 637            sb.append("\n\tNumber of locked synchronizers = " + locks.length);
 638            sb.append('\n');
 639            for (LockInfo li : locks) {
 640                sb.append("\t- " + li);
 641                sb.append('\n');
 642            }
 643        }
 644        sb.append('\n');
 645        return sb.toString();
 646     }
 647     private static final int MAX_FRAMES = 8;
 648 
 649     /**
 650      * Returns a <tt>ThreadInfo</tt> object represented by the
 651      * given <tt>CompositeData</tt>.
 652      * The given <tt>CompositeData</tt> must contain the following attributes
 653      * unless otherwise specified below:
 654      * <blockquote>
 655      * <table border summary="The attributes and their types the given CompositeData contains">
 656      * <tr>
 657      *   <th align=left>Attribute Name</th>
 658      *   <th align=left>Type</th>
 659      * </tr>
 660      * <tr>




 562      *
 563      * @return <tt>true</tt> if the thread is executing native code;
 564      *         <tt>false</tt> otherwise.
 565      */
 566     public boolean isInNative() {
 567          return inNative;
 568     }
 569 
 570     /**
 571      * Returns a string representation of this thread info.
 572      * The format of this string depends on the implementation.
 573      * The returned string will typically include
 574      * the {@linkplain #getThreadName thread name},
 575      * the {@linkplain #getThreadId thread ID},
 576      * its {@linkplain #getThreadState state},
 577      * and a {@linkplain #getStackTrace stack trace} if any.
 578      *
 579      * @return a string representation of this thread info.
 580      */
 581     public String toString() {
 582         StringBuilder sb = new StringBuilder();
 583         sb.append('"').append(getThreadName()).append('"')
 584                 .append(" Id=").append(getThreadId()).append(' ')
 585                 .append(getThreadState());
 586 
 587         if (getLockName() != null) {
 588             sb.append(" on ").append(getLockName());
 589         }
 590         if (getLockOwnerName() != null) {
 591             sb.append(" owned by \"").append(getLockOwnerName())
 592                     .append("\" Id=").append(getLockOwnerId());
 593         }
 594         if (isSuspended()) {
 595             sb.append(" (suspended)");
 596         }
 597         if (isInNative()) {
 598             sb.append(" (in native)");
 599         }
 600         sb.append('\n');
 601         int i = 0;
 602         for (; i < stackTrace.length && i < MAX_FRAMES; i++) {
 603             StackTraceElement ste = stackTrace[i];
 604             sb.append("\tat ").append(ste);
 605             sb.append('\n');
 606             if (i == 0 && getLockInfo() != null) {
 607                 Thread.State ts = getThreadState();
 608                 switch (ts) {
 609                     case BLOCKED:
 610                         sb.append("\t-  blocked on ").append(getLockInfo());
 611                         sb.append('\n');
 612                         break;
 613                     case WAITING:
 614                         sb.append("\t-  waiting on ").append(getLockInfo());
 615                         sb.append('\n');
 616                         break;
 617                     case TIMED_WAITING:
 618                         sb.append("\t-  waiting on ").append(getLockInfo());
 619                         sb.append('\n');
 620                         break;
 621                     default:
 622                 }
 623             }
 624 
 625             for (MonitorInfo mi : lockedMonitors) {
 626                 if (mi.getLockedStackDepth() == i) {
 627                     sb.append("\t-  locked ").append(mi);
 628                     sb.append('\n');
 629                 }
 630             }
 631        }
 632        if (i < stackTrace.length) {
 633            sb.append("\t...");
 634            sb.append('\n');
 635        }
 636 
 637        LockInfo[] locks = getLockedSynchronizers();
 638        if (locks.length > 0) {
 639            sb.append("\n\tNumber of locked synchronizers = ").append(locks.length);
 640            sb.append('\n');
 641            for (LockInfo li : locks) {
 642                sb.append("\t- ").append(li);
 643                sb.append('\n');
 644            }
 645        }
 646        sb.append('\n');
 647        return sb.toString();
 648     }
 649     private static final int MAX_FRAMES = 8;
 650 
 651     /**
 652      * Returns a <tt>ThreadInfo</tt> object represented by the
 653      * given <tt>CompositeData</tt>.
 654      * The given <tt>CompositeData</tt> must contain the following attributes
 655      * unless otherwise specified below:
 656      * <blockquote>
 657      * <table border summary="The attributes and their types the given CompositeData contains">
 658      * <tr>
 659      *   <th align=left>Attribute Name</th>
 660      *   <th align=left>Type</th>
 661      * </tr>
 662      * <tr>