Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement