concurrency - Java thread id not changing -


i'm trying unit test class containing threadlocal , wish make tests not affect each other starting new thread in each test. however, still do, , don't understand why.

@test public void testthread() {     system.out.println(thread.currentthread().getid());     new thread(){         @override         public void run(){             system.out.println(thread.currentthread().getid());         }     }.run(); } 

output:

1 1 

can explain why ids same though new thread started?

you should call start method on thread, not run method. if call run, running in same thread.


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -