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>

@@ -577,19 +577,21 @@
      * and a {@linkplain #getStackTrace stack trace} if any.
      *
      * @return a string representation of this thread info.
      */
     public String toString() {
-        StringBuilder sb = new StringBuilder("\"" + getThreadName() + "\"" +
-                                             " Id=" + getThreadId() + " " +
-                                             getThreadState());
+        StringBuilder sb = new StringBuilder();
+        sb.append('"').append(getThreadName()).append('"')
+                .append(" Id=").append(getThreadId()).append(' ')
+                .append(getThreadState());
+
         if (getLockName() != null) {
-            sb.append(" on " + getLockName());
+            sb.append(" on ").append(getLockName());
         }
         if (getLockOwnerName() != null) {
-            sb.append(" owned by \"" + getLockOwnerName() +
-                      "\" Id=" + getLockOwnerId());
+            sb.append(" owned by \"").append(getLockOwnerName())
+                    .append("\" Id=").append(getLockOwnerId());
         }
         if (isSuspended()) {
             sb.append(" (suspended)");
         }
         if (isInNative()) {

@@ -597,34 +599,34 @@
         }
         sb.append('\n');
         int i = 0;
         for (; i < stackTrace.length && i < MAX_FRAMES; i++) {
             StackTraceElement ste = stackTrace[i];
-            sb.append("\tat " + ste.toString());
+            sb.append("\tat ").append(ste);
             sb.append('\n');
             if (i == 0 && getLockInfo() != null) {
                 Thread.State ts = getThreadState();
                 switch (ts) {
                     case BLOCKED:
-                        sb.append("\t-  blocked on " + getLockInfo());
+                        sb.append("\t-  blocked on ").append(getLockInfo());
                         sb.append('\n');
                         break;
                     case WAITING:
-                        sb.append("\t-  waiting on " + getLockInfo());
+                        sb.append("\t-  waiting on ").append(getLockInfo());
                         sb.append('\n');
                         break;
                     case TIMED_WAITING:
-                        sb.append("\t-  waiting on " + getLockInfo());
+                        sb.append("\t-  waiting on ").append(getLockInfo());
                         sb.append('\n');
                         break;
                     default:
                 }
             }
 
             for (MonitorInfo mi : lockedMonitors) {
                 if (mi.getLockedStackDepth() == i) {
-                    sb.append("\t-  locked " + mi);
+                    sb.append("\t-  locked ").append(mi);
                     sb.append('\n');
                 }
             }
        }
        if (i < stackTrace.length) {

@@ -632,14 +634,14 @@
            sb.append('\n');
        }
 
        LockInfo[] locks = getLockedSynchronizers();
        if (locks.length > 0) {
-           sb.append("\n\tNumber of locked synchronizers = " + locks.length);
+           sb.append("\n\tNumber of locked synchronizers = ").append(locks.length);
            sb.append('\n');
            for (LockInfo li : locks) {
-               sb.append("\t- " + li);
+               sb.append("\t- ").append(li);
                sb.append('\n');
            }
        }
        sb.append('\n');
        return sb.toString();