Let us understand this one step at time.
For starters, I will try answering few questions that may have crossed your mind.
a) Are you creating multiple threads?
Ans. Yes for sure, you are creating 101 logical threads (1 main thread + 100 other by calling start() method of thread). By logical I mean is that there are not actual 100 parallel threads, instead they are mapped to the core kernel threads (basically the number of cores).
Each core has a work queue and the logical threads gets assigned to the cores. It may so happen (lets say in a dual core machine) that one of the core is so busy in processing some task that all the application threads (created by your program) gets mapped to the same core.
It is the decision of JVM how to map the threads and to schedule the logical threads and its execution time as well.
b) What happens when you call start()?
Ans. A good and precise overview on the life cycle of the thread is available at: http://www.javatpoint.com/life-cycle-of-a-thread.
To highlight, calling start() method does not entitle a thread to be in the running state. It has to be picked up by the Thread scheduler to get into that state. Hence not all threads started by the program may be actually running in parallel.
c) So what has happened here having said that?
Ans. In your case, the task is so small that JVM decides to let go of one thread before scheduling another thread. Because according to JVM, if it does not do so, lot of time will be wasted in acquiring and releasing CPU resources and hence a lot of time will be wasted in context switching.
There goes your general explanation.
- What are you understanding wrong here?
Ans. To get an exception, some one must have to throw an exception first. The entire code does nothing to generate an exception.
You are setting "name" to a new reference with every thread and not modifying the state of the String (which actually are immutable in JAVA).
Does a developer who is developing an api (like Collections api in java) should manually throw ConcurrentModificationException when two threads try to modify the object's data?
Ans. An API which is not entitled to be thread safe should throw ConcurrentModificationException if the state can be modified by multiple threads and can impact the user seeing the corresponding state of the data structure (like ArrayList, HashMap etc.)