>> Only if the object's class extends Thread. Even then the construction
>> runs in the thread where the "new" expression occurs. The new thread
>> only actually begins to run when its "start" method (inherited from
>> Thread) is invoked.
........
> Twisted was referring to threads spawned by application code. Ishwor
> seems to be talking about threads managed internally by the JVM, such as
> the garbage collector (GC) thread.
Yeah.tongue-in-cheek. :-?
> Threads do get created in the JVM, but the ones of interest are the
> application threads, of which there is only one until the programmer
> decides otherwise.
Yes agreed.
>> (running as java/java.exe) but the fragments that we initialise, i.e., in
>> OPs case, the object "e". Isn't it a thread in JVM? it def can't be a
>> process. ??? any ideas?
>
> No, construction does not spawn a new thread.
Loosing some foundation here... Internally in the JVM, how is the object "e"
represented? It'll well be an instance of a class in the heap but that's
not what I intended to ask. Apologies. What I wanted to ask (without
forking a seperate discussion thread :-) was how threading works at JVM
level.
>> Let me sort of rephrase my question, javac/javac.exe creates one big
>> chunk of bytecode, JVM reads line by line of that bytecode and
[quoted text clipped - 4 lines]
> The application is not a process to the OS (usually), but java is. That
> doesn't mean it's automatically multithreaded, other than the GC thread.
Yes, java will look like any other process to the OS. But how are different
_instances_ of different non-related class represented in JVM? This seems
to point me to the assumption, that the classes are indeed executing as
threads in JVM.
> Whatever threads a Java application has, including the one main thread,
> are
> part of the "java" process. That is correct.
Yup.
> It doesn't explain anything regarding the OP's question.
I didn't. As I mentioned above, I wanted to ask a question without forking a
seperate discussion thread. Apologies for hijacking the thread.
> The OP had asked if constructing an object spawned a new thread. It does
> not.
Yes, but how about in the JVM? Is there a tutorial on how JVM works
somewhere? Perhaps tucked neatly instead of Sun's
lengthy-full-of-mathematical-symbol ones? :P
Thanks!

Signature
Cheers,
Ishwor Gurung
/* humpty dumpty */
Lew - 23 Aug 2007 18:54 GMT
Lew wrote:
> Loosing some foundation here... Internally in the JVM, how is the object "e"
> represented? It'll well be an instance of a class in the heap but that's
> not what I intended to ask. Apologies. What I wanted to ask (without
> forking a seperate discussion thread :-) was how threading works at JVM
> level.
Threading works by spawning a new OS thread and executing code in that thread.
The object "e" is represented by a data structure on the heap. It has nothing
to do with threading. There is bytecode at a location in the JVM that
represents the data and methods of the object.
> Yes, java will look like any other process to the OS. But how are different
> _instances_ of different non-related class represented in JVM? This seems
> to point me to the assumption, that the classes are indeed executing as
> threads in JVM.
They aren't. Different instances are represented as separate collections of
data on the heap.
>> The OP had asked if constructing an object spawned a new thread. It does
>> not.
>
> Yes, but how about in the JVM? Is there a tutorial on how JVM works
> somewhere? Perhaps tucked neatly instead of Sun's
> lengthy-full-of-mathematical-symbol ones? :P
I don't understand what you're asking, really. Construction of an object does
not spawn a new thread, not in the JVM, not anywhere, not nohow. (Of course,
it is possible that someone somewhere might write a JVM that violates this,
but it doesn't change the conceptual model. Anyhow, no JVM I've heard of does
violate this.)
Threads and construction are orthogonal concepts.
I don't know about tutorials about specific JVM implementations. There are
several JVMs out there. The JLS defines precisely how it must behave, though.
I really think I am not understanding your question. I am confused by how
people keep talking about constructors and threads in the same breath. What
are you actually asking?

Signature
Lew
Joshua Cranmer - 23 Aug 2007 19:10 GMT
> I don't know about tutorials about specific JVM implementations. There
> are several JVMs out there. The JLS defines precisely how it must
> behave, though.
Actually, the Virtual Machine Specification defines precisely how JVMs
must behave. The JLS only defines how Java code must behave.

Signature
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
Mark Space - 23 Aug 2007 19:17 GMT
> Loosing some foundation here... Internally in the JVM, how is the object "e"
> represented?
Google will help you here. Here's one page I found doing a search for
"java threads internals":
http://www.artima.com/insidejvm/ed2/jvm6.html
> It'll well be an instance of a class in the heap but that's
> not what I intended to ask. Apologies. What I wanted to ask (without
> forking a seperate discussion thread :-) was how threading works at JVM
> level.
There's no one way for all JVMs to implement threading. Sun left the
specification vague so that each platform can implement threads as it
sees fit.
Some hints here:
http://www.artima.com/insidejvm/ed2/jvm11.html
You should make and refine your own Google searches if you need more
information.
> Yes, java will look like any other process to the OS. But how are different
> _instances_ of different non-related class represented in JVM?
Bytes on the heap; sometimes bytes on the stack.
> This seems
> to point me to the assumption, that the classes are indeed executing as
> threads in JVM.
No. Never. You seem to have a grave misunderstanding of JVMs and maybe
programming in general.
> Yes, but how about in the JVM? Is there a tutorial on how JVM works
> somewhere? Perhaps tucked neatly instead of Sun's
> lengthy-full-of-mathematical-symbol ones? :P
Google is your friend.
http://www.google.com/search?q=java+threads+internals
Roedy Green - 23 Aug 2007 23:44 GMT
On Thu, 23 Aug 2007 18:17:22 GMT, Mark Space
<markspace@sbc.global.net> wrote, quoted or indirectly quoted someone
who said :
>There's no one way for all JVMs to implement threading. Sun left the
>specification vague so that each platform can implement threads as it
>sees fit.
Usually Threads map onto OS threads, but sometimes threads are faked
splitting one OS thread into several Java threads. The second
approach has lower overhead per thread, but does not allow
simultaneous execution in a dual CPU.
see http://mindprod.com/jgloss/thread.html#GREEN

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Ishwor Gurung - 24 Aug 2007 04:05 GMT
Hi Mark,
> http://www.artima.com/insidejvm/ed2/jvm6.html
one was indeed helpful.
......
> Some hints here:
>
> http://www.artima.com/insidejvm/ed2/jvm11.html
I found this http://www.artima.com/insidejvm/ed2/jvm2.html very helpful as
well :)
........
> http://www.google.com/search?q=java+threads+internals
Above result was using this query.
Also a very helpful one i found was by Bill Venners -
http://www.artima.com/insidejvm/ed2/jvm.html
Thanks a lot guys.

Signature
Cheers,
Ishwor Gurung
/* humpty dumpty */
Ishwor Gurung - 24 Aug 2007 04:08 GMT
.....
>> Some hints here:
>>
>> http://www.artima.com/insidejvm/ed2/jvm11.html
>
> I found this http://www.artima.com/insidejvm/ed2/jvm2.html very helpful as
....
> Also a very helpful one i found was by Bill Venners -
^^^^^^^^^^^^
Same guy who wrote http://www.artima.com/insidejvm/ed2/jvm11.html

Signature
Cheers,
Ishwor Gurung
/* humpty dumpty */