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

How to logout from a login page in asp.net -

Stack level too deep error after upgrade to rails 3.2 and ruby 1.9.3 -