Notice how all these variables are declared static. That means there is normally only ever one.
To make threadId thread specific we use threadlocal. Which means instead of there being one instance there will now be one instance per thread.
In your version each time we call get() it will return a different number.
In the original version the first time get is called it will initialise itself and save the value on the thread. This value will be returned for each subsequent call to get on that thread.
your code
//in thread 0
ThreadId.get() //return 0
//in thread 1
ThreadId.get() //return 1
//in thread 0
ThreadId.get() //return 2
//in thread 1
ThreadId.get() //return 3
//in thread 0
ThreadId.get() //return 4
original code
//in thread 0
ThreadId.get() //return 0
//in thread 1
ThreadId.get() //return 1
//in thread 0
ThreadId.get() //return 0
//in thread 1
ThreadId.get() //return 1
//in thread 0
ThreadId.get() //return 0