This is some information on the Java 6 certification that I prepare. This information is not very well structured and it is most of the time an answer to the questions that come when I read the SCJP 6 book (Bates and Sierra).
*** AS OF 5 OF MARCH 2010, I AM SCJP 6.0 ***

The instance variable "a" was not modified because for every thread there is a different "a" !

public class Main {

public static void main(String[] args) {

// 2nd version the thread will share the same object

ClassA ca = new ClassA();

Thread thread;

for(int i=0; i < 10; i++) {

thread = new Thread(ca);

thread.start();

//new Thread(new ClassA()).start();

}

}

}

run:

Thread-0

a : Thread-0 sleeping 5 seconds...

Thread-1

a : Thread-1 sleeping 5 seconds...

Thread-2

a : Thread-2 sleeping 5 seconds...

Thread-3

a : Thread-3 sleeping 5 seconds...

Thread-5

a : Thread-5 sleeping 5 seconds...

Thread-7

a : Thread-7 sleeping 5 seconds...

Thread-9

a : Thread-9 sleeping 5 seconds...

Thread-4

a : Thread-4 sleeping 5 seconds...

Thread-6

a : Thread-6 sleeping 5 seconds...

Thread-8

a : Thread-8 sleeping 5 seconds...

a : Thread-8-Thread-0 after sleeping 5 seconds...

a : Thread-8-Thread-1 after sleeping 5 seconds...

a : Thread-8-Thread-2 after sleeping 5 seconds...

a : Thread-8-Thread-5 after sleeping 5 seconds...

a : Thread-8-Thread-3 after sleeping 5 seconds...

a : Thread-8-Thread-7 after sleeping 5 seconds...

a : Thread-8-Thread-9 after sleeping 5 seconds...

a : Thread-8-Thread-4 after sleeping 5 seconds...

a : Thread-8-Thread-6 after sleeping 5 seconds...

a : Thread-8-Thread-8 after sleeping 5 seconds...

BUILD SUCCESSFUL (total time: 11 seconds)

The thread "8" had a big influence on all the others threads because the thread "8" modified the instance variable "a" ! In fact it is because this poor thread "8" was the last to be started and as he is the last, he modified the same "a" instance variable for all the threads !!!

You can share the same objects. You will avoid to waste memory... But if your threads modify the data... You have to find a way keep the operations/data modifications consistent... In other words all the operations you do that can corrupt the data have to be atomic to avoid the corruption...