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
Post a Comment