Page 1 of 2 12 LastLast
Results 1 to 20 of 24
  1. #1
    rajinder5 is offline Member
    Join Date
    Oct 2010
    Posts
    17
    Rep Power
    0

    Default is it mutithreading?

    hi!

    if i run same program (say its name is "hello" in file hello.java) with two different "java" commands as:

    >java hello rajinder

    >java hello prince


    where rajinder and prince are command line arguments.

    is this multithreading??? ...i mean the two java commands will run the same hello program as two different processes or as the two different threads of same program???

    thanks in advance...

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    You could try try reading and writing some static data in the Hello class.

  3. #3
    audriusa is offline Member
    Join Date
    Oct 2010
    Posts
    7
    Rep Power
    0

    Default

    When you run the same program twice in parallel, these are usually called processes, not threads. Threads are understood as parts of the same Java virtual machine that share most of the accessible memory (processes normally run in dedicated memory space and may only share tiny parts for data exchange). Hence thread is more lightweight than a process.

    If you modify static fields in one process, this should have no any effect on the field values in another process. It does not matter that classes are loaded from the same files. Only system classes may be shared in some advanced implementations but this is likely done in a transparent way.
    Last edited by audriusa; 10-06-2010 at 07:39 AM.

  4. #4
    rajinder5 is offline Member
    Join Date
    Oct 2010
    Posts
    17
    Rep Power
    0

    Default

    is running two "java" commands means running two different JVMs???

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by rajinder5 View Post
    is running two "java" commands means running two different JVMs???
    Yep, but when you look in the bin directory of your jre you'd see that most of the jvm is implemented as a bunch of .dll files so the machine code that makes up your Java virtual machine will only be loaded in memory once.

    kind regards,

    Jos

  6. #6
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    Quote Originally Posted by JosAH View Post
    Yep, but when you look in the bin directory of your jre you'd see that most of the jvm is implemented as a bunch of .dll files so the machine code that makes up your Java virtual machine will only be loaded in memory once.

    kind regards,

    Jos
    I secondarily agree with this.
    Every project, package, class, method, variable, syntax, algorithm, etc.
    are registered in my memory bank. Thanks to this thread.

  7. #7
    rajinder5 is offline Member
    Join Date
    Oct 2010
    Posts
    17
    Rep Power
    0

    Default

    thanks for responding... :)

  8. #8
    rajinder5 is offline Member
    Join Date
    Oct 2010
    Posts
    17
    Rep Power
    0

    Default

    like "java", will "javac" also counted under JVM... i mean is it also part of JVM??

    JVM's work is to load the classes and execute them. is compiling the java programs to bytecode also considered as the work of JVM???

    thanks...

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by rajinder5 View Post
    like "java", will "javac" also counted under JVM... i mean is it also part of JVM??

    JVM's work is to load the classes and execute them. is compiling the java programs to bytecode also considered as the work of JVM???
    Nope, the compiler can be written in BrainF*ck (*) for that matter, as long as it produces valid classes. It is a good tradition to write a compiler for a language X in language X itself and so is javac written in Java but it is not part of the jvm.

    kind regards,

    Jos

    (*) I sincerely doubt that anyone can write a compiler in BrainF*ck ;-)

  10. #10
    somanayr is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

    Default

    This isn't multithreading. This is just running two processes. If you have two threads going, they're in the same process. Threads cannot be called from command prompt, only from within the JVM.

  11. #11
    rajinder5 is offline Member
    Join Date
    Oct 2010
    Posts
    17
    Rep Power
    0

    Default

    hi!

    dear JosAH! perhaps u only can write compiler in BrainF*ck language and i m sure u will write one day. ;-) i definitely cannot!!!

    by the way, can an application have multiple processes running at the same time like multiple threads??? i mean ... do concurrently running processes always belong to different applications/programs(like winword and winamp) or they can also belong to same applications(winword only)???

    thanks...

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,967
    Rep Power
    19

    Default

    Processes belong to the OS.
    Threads belong to a process (program).

    I can write a program that'll launch a load of processes and then exit and those processes could (depending on what they do) still be running.

    I could also write a program that creates a load of Threads, but when that Java process exits so do those threads.

  13. #13
    rajinder5 is offline Member
    Join Date
    Oct 2010
    Posts
    17
    Rep Power
    0

    Default

    hi Tolls!!!

    do u mean that a program/application(say WINWORD) can have multiple processes running concurrently within it and each process, in turn, can have multiple threads running in it concurrently???

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,967
    Rep Power
    19

    Default

    No.
    Your WINWORD is a process.

    It might launch other processes (in Java via the runtime exec() stuff), but it doesn't own them.

  15. #15
    somanayr is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

    Default

    Quote Originally Posted by rajinder5 View Post
    hi Tolls!!!

    do u mean that a program/application(say WINWORD) can have multiple processes running concurrently within it and each process, in turn, can have multiple threads running in it concurrently???
    Yah. Winword can have multiple threads... probably does. That way one thread can listen for keystrokes while another handles screen output. That would mean that keystrokes aren't lost during a lag.

    My computer is running on 790 threads and 68 processes. If that says anything...

  16. #16
    rajinder5 is offline Member
    Join Date
    Oct 2010
    Posts
    17
    Rep Power
    0

    Default

    so do u mean that processes always belong to OS i.e. all applications or softwares( eg winword ,winamp, media players etc.) running on an OS (say windows platform) are procesess and each such process can have multiple threads???

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,967
    Rep Power
    19

    Default

    You probably ought to go and read up on this properly, since you seem to want something detailed.

    My stuff above is a basic rule of thumb (or ROT if you prefer), and done froma Java perspective (this is after all a Java forum). For example, a Unix command window can own several processes, and it is itself a process. So if the terminal is closed then those processes are often shutdown as well, though they can be orphaned (essentially taken over by the OS). It's not as clearcut as I'm making out.

    But, a thread (in Java terms) is owned by the program, and dies with the program. A process does not (in Java terms)...necessarily.

  18. #18
    rajinder5 is offline Member
    Join Date
    Oct 2010
    Posts
    17
    Rep Power
    0

    Default

    thanks tolls!!!

    one question regarding "locks/monitors".

    suppose a thread acquire class lock on a class named "xyz" . is this same as acquiring lock on xyz.class (instance of class Class)???

  19. #19
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,967
    Rep Power
    19

    Default

    I think so, but you'd do better to get someone more used to synchronising than me. I try and avoid getting myself into the position of needing stuff like that.

  20. #20
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by rajinder5 View Post
    thanks tolls!!!

    one question regarding "locks/monitors".

    suppose a thread acquire class lock on a class named "xyz" . is this same as acquiring lock on xyz.class (instance of class Class)???
    Yep, according to the JLS:

    Quote Originally Posted by JLS
    8.4.3.6 synchronized Methods

    A synchronized method acquires a monitor (17.1) before it executes. For a class (static) method, the monitor associated with the Class object for the method's class is used. For an instance method, the monitor associated with this (the object for which the method was invoked) is used.
    kind regards,

    Jos

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •