public class BBDifferencetest {
static AtomicInteger testnum = new AtomicInteger();
public static void testStringBuilder() {
final StringBuffer sb = new StringBuffer();
Thread t1 = new Thread() {
@Override
public void run() {
for (int x = 0; x < 60; x++) {
testnum .getAndIncrement();
sb.append(testnum );
sb.append(" ");
}
}
};
Thread t2 = new Thread() {
public void run() {
for (int x = 0; x < 60; x++) {
testnum .getAndIncrement();
sb.append(testnum );
sb.append(" ");
}
}
};
t1.start();
t2.start();
try {
t1.join();
t2.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Result string is: " + sb.toString());
}
public static void main(String args[]) {
testStringBuilder();
}
}