Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

Do I get Physical Thread in Java?

Thread view: 
dimitrik107@hotmail.com - 20 Aug 2006 19:17 GMT
When you write Thread t = new MyThread(); r.start(), do you get a new
thread (you know like in Linux you call pthread_create() and kernel
gives you a new thread for running). Maybe java is optimizing and JVM
will not call pthread_create when you new your thrread?

If anyone know, please explain; thank you.
Mike Schilling - 20 Aug 2006 19:35 GMT
> When you write Thread t = new MyThread(); r.start(), do you get a new
> thread (you know like in Linux you call pthread_create() and kernel
> gives you a new thread for running). Maybe java is optimizing and JVM
> will not call pthread_create when you new your thrread?
>
> If anyone know, please explain; thank you.

This is up to the JVM implementation. The Java standard decribess how
threads behave, but whether they're implemented with OS-level threads, a
lightweight threading package, or by having a single-threaded interpreter
round-robin among the active threads is left open.
zero - 20 Aug 2006 19:47 GMT
>> When you write Thread t = new MyThread(); r.start(), do you get a new
>> thread (you know like in Linux you call pthread_create() and kernel
[quoted text clipped - 7 lines]
> a lightweight threading package, or by having a single-threaded
> interpreter round-robin among the active threads is left open.

Furthermore, the whole point of java is not having to worry about stuff
like this.  If you do, you're probably either using the wrong tool (try
C++) or going about your problem the wrong way.  There may be legitimate
reasons to rely on this information in java, but I can't think of any.
Arne Vajhøj - 20 Aug 2006 20:12 GMT
> Furthermore, the whole point of java is not having to worry about stuff
> like this.  If you do, you're probably either using the wrong tool (try
> C++) or going about your problem the wrong way.  There may be legitimate
> reasons to rely on this information in java, but I can't think of any.

It can be very relevant to know the implementation of
Java threads on ones platform for both application,
operating system and hardware configuration.

Arne
Patricia Shanahan - 20 Aug 2006 21:21 GMT
>>> When you write Thread t = new MyThread(); r.start(), do you get a new
>>> thread (you know like in Linux you call pthread_create() and kernel
[quoted text clipped - 11 lines]
> C++) or going about your problem the wrong way.  There may be legitimate
> reasons to rely on this information in java, but I can't think of any.

What about programs that need more than one second of CPU time per
second of elapsed time? Multiple OS threads can run on different
processors at the same time. A single OS thread can never get more than
one processor.

Patricia
Mike Schilling - 20 Aug 2006 23:02 GMT
>>>> When you write Thread t = new MyThread(); r.start(), do you get a
>>>> new thread (you know like in Linux you call pthread_create() and
[quoted text clipped - 17 lines]
> processors at the same time. A single OS thread can never get more
> than one processor.

Yes.  If the OP's question were qualified to be asking about a specific Java
implementation (including version), it could be answered in detail, and that
detail might be of real importance.  It's a fallacy to conclude from "Java
can be used to write very portable applications" that "Java should *only* be
used to write very portable applications."
Chris Uppal - 21 Aug 2006 10:52 GMT
> Furthermore, the whole point of java is not having to worry about stuff
> like this.  If you do, you're probably either using the wrong tool (try
> C++) or going about your problem the wrong way.  There may be legitimate
> reasons to rely on this information in java, but I can't think of any

Unfortunately, that is almost completely untrue.  In an ideal world it /would/
be true, but this is not that world...

The design space which can be approached by "green" threads has only a small
overlap with the design space which is suitable for OS-level threads -- unless
the OS itself provides light-weight threads, and that is in general /not/ the
case (there are exceptions).

If you are only using a small number of threads, and do not care greatly about
the amount of actual concurrency you achieve -- i.e you are using the threads
only as a code structuring mechanism -- then it makes little difference how the
threads are implemented.  For all the other cases, you do have to care, and you
may be forced to use /very/ different designs for your application depending on
how threads are implemented.

   -- chris
Arne Vajhøj - 20 Aug 2006 20:09 GMT
>> When you write Thread t = new MyThread(); r.start(), do you get a new
>> thread (you know like in Linux you call pthread_create() and kernel
[quoted text clipped - 5 lines]
> lightweight threading package, or by having a single-threaded interpreter
> round-robin among the active threads is left open.

It would probably be impossible to define something like this
in the Java standard, because Java runs on so many different
platform.

But I believe that recent Java versions for common platforms
tend to map Java threads to native threads 1:1.

Some Java implementations has a -X or -XX switch to specify
the threading model to use.

Arne
Martin Gregorie - 20 Aug 2006 22:13 GMT
>>> When you write Thread t = new MyThread(); r.start(), do you get a new
>>> thread (you know like in Linux you call pthread_create() and kernel
[quoted text clipped - 12 lines]
> But I believe that recent Java versions for common platforms
> tend to map Java threads to native threads 1:1.

That's been true for Sun's JDK for Linux from at least version 1.3 - its
easy to prove: start a Java app from one console window, switch to
another, type "ps -u/username/" and look at all the processes[1] with
the same name as the Java app.

[1] Like most Unices, Linux uses the same mechanism to schedule and
execute both threads and processes.

Signature

martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

dimitrik107@hotmail.com - 20 Aug 2006 23:24 GMT
Sorry I see my question should be more specific about OS. So, for
Operating System Microsoft Windows XP Professional
Operating System Version 5.1.2600 (dual Intel(R) Pentium(R) 4 CPU
3.00GHz)

JVM version 1.5.0_07

Can anyone please answre my question and what I should set for flags to
java.exe or javac.exe so I get (if possible) one thread per call to
Thread t= new Thread(); t.run()

Thank you and also thanks for people who posted about this knowledge
being useful.
Arne Vajhøj - 20 Aug 2006 23:41 GMT
> Sorry I see my question should be more specific about OS. So, for
> Operating System Microsoft Windows XP Professional
[quoted text clipped - 6 lines]
> java.exe or javac.exe so I get (if possible) one thread per call to
> Thread t= new Thread(); t.run()

SUN Java / Windows / x86 is 1 Java thread = 1 Windows thread

Arne


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.