Advertisement
Guest User

Untitled

a guest
Mar 7th, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. public class BBDifferencetest {
  2.     static AtomicInteger testnum  = new AtomicInteger();
  3.      
  4.      public static void testStringBuilder() {
  5.              final StringBuffer sb = new StringBuffer();
  6.  
  7.              Thread t1 = new Thread() {
  8.  
  9.                      @Override
  10.                      public void run() {
  11.                              for (int x = 0; x < 60; x++) {
  12.                                      testnum .getAndIncrement();
  13.                                      sb.append(testnum );
  14.                                      sb.append(" ");                                
  15.                              }
  16.                      }
  17.              };
  18.              Thread t2 = new Thread() {
  19.  
  20.                      public void run() {
  21.  
  22.                              for (int x = 0; x < 60; x++) {
  23.                                      testnum .getAndIncrement();
  24.                                      sb.append(testnum );
  25.                                      sb.append(" ");
  26.                              }
  27.                      }
  28.              };
  29.              t1.start();
  30.              t2.start();
  31.            
  32.              try {
  33.                      t1.join();
  34.                      t2.join();
  35.              } catch (InterruptedException e) {
  36.                      e.printStackTrace();
  37.              }
  38.            
  39.              System.out.println("Result string is: " + sb.toString());
  40.              
  41.         }
  42.  
  43.      public static void main(String args[]) {
  44.              testStringBuilder();
  45.      }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement