A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Servlets
Author
Thread Id Problem
sonu raj
Ranch Hand
Joined: Jul 31, 2012
Posts: 33
I like...
posted
Aug 06, 2012 03:08:33
0
class Abc implements Runnable { public void run() { long l=Thread.currentThread().getId(); System.out.println(l); } public static void main(String a[]) { Thread t1=new Thread(new Abc()); Thread t2=new Thread(new Abc()); t1.start(); t2.start(); } }
When I compile and run the above program I always gets the same output:
i.e.
9
10
I want to know why the output is always 9 and 10, why not 2 and 4 or 4 and 5.etc
Please elaborate!!
[Added code tags - see
UseCodeTags
]
Jaikiran Pai
Marshal
Joined: Jul 20, 2005
Posts: 8145
52
I like...
posted
Aug 06, 2012 03:31:06
0
Closing this thread since this is a duplicate of
http://www.coderanch.com/t/589095/threads/java/Thread-Id
. Sonu, please do not create multiple threads for the same question.
[
My Blog
] [
JavaRanch Journal
]
I agree. Here's the link:
http://aspose.com/file-tools
subject: Thread Id Problem
Similar Threads
join() method in Thread doesn't work as expected
Output even more unexpected than I was expecting!
Explain output of this program
join() in Threads
A hard question
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter