Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: Process and Multi-threading

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 10 Times in 4 Posts

    Default Process and Multi-threading

    I cannot make this stop watch:- work. pls help. I have no clue of what is required in the test processBuilder.
    Attached Files Attached Files

  2. The Following 3 Users Say Thank You to Pacesetter For This Useful Post:

    lwigfulltiffany (March 27th, 2019), rarberryrock (March 26th, 2019), srgisjeff (March 26th, 2019)


  3. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Process and Multi-threading

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please simply post your code correctly using code or highlight tags per the above link rather than attaching it.

  4. The Following 3 Users Say Thank You to GregBrannon For This Useful Post:

    lwigfulltiffany (March 27th, 2019), rarberryrock (March 26th, 2019), srgisjeff (March 26th, 2019)

  5. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 10 Times in 4 Posts

    Default Re: Process and Multi-threading

    still trying to figure out how files are easily implemented here.

  6. The Following 3 Users Say Thank You to Pacesetter For This Useful Post:

    lwigfulltiffany (March 27th, 2019), rarberryrock (March 26th, 2019), srgisjeff (March 26th, 2019)

  7. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Process and Multi-threading

    What's your question? How can we help?

  8. The Following 2 Users Say Thank You to GregBrannon For This Useful Post:

    lwigfulltiffany (March 27th, 2019), srgisjeff (March 26th, 2019)

  9. #5
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 10 Times in 4 Posts

    Default Process and Multi-threading

    Hello everyone,

    I have tried several methods of creating threads to get this stop watch working. created a thread class which implements runnable but it seems not helping. Really can't get this working. pls i know it involves a couple of codes but am totally blank right now.
    Attached Files Attached Files

  10. The Following 2 Users Say Thank You to Pacesetter For This Useful Post:

    lwigfulltiffany (March 27th, 2019), srgisjeff (March 26th, 2019)

  11. #6
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 10 Times in 4 Posts

    Default Process and Multi-threading

    In order to not block the command shell when a process is created we
    will create a thread that manages the running of each application.
    Create a new class that implements the Runnable interface and which
    takes the string command as input in the constructor. This will be the
    class that calls ProcessBuilder in its run method. Observe that since we
    need to have access to the string command in the run method of the
    thread, we need to store this when the thread is created. In the run
    method we add the code from the old version of the method
    createProcess and modify the method createProcess as follows: Instead
    of calling ProcessBuilder in this method you should create an instance
    of the Runnable class. Then start the Runnable as a thread.
    Attached Files Attached Files

  12. The Following 2 Users Say Thank You to Pacesetter For This Useful Post:

    lwigfulltiffany (March 27th, 2019), srgisjeff (March 26th, 2019)

  13. #7
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Process and Multi-threading

    Please don't start duplicate threads. Threads merged.

    Answer questions, post details, do what you're asked to do, and keep the dialog going. Source files end with a .java extension. What are the .txt files you've attached? Copy your source files and paste them directly into a post using code or highlight tags as described in the link I provided earlier.

    Then explain what help you need. We're not going to read your assignment, all of the code you've attached, and figure out what is needed to get something "working". Tell us what you've done, what results you've gotten, how those results are unsatisfactory (what should they be), why you think that might be, and then ask what what to do to modify the code so that it meets the requirements.

  14. The Following 3 Users Say Thank You to GregBrannon For This Useful Post:

    lwigfulltiffany (March 27th, 2019), rarberryrock (March 26th, 2019), srgisjeff (March 26th, 2019)

  15. #8

    Default Re: Process and Multi-threading

    Both processes and threads are independent sequences of execution. The typical difference is that threads run in a shared memory space, while processes run in separate memory spaces.

    I'm not sure what "hardware" vs "software" threads you might be referring to. Threads are an operating environment feature, rather than a CPU feature.

    Erlang uses the term "process" because it does not expose a shared-memory multiprogramming model. Calling them "threads" would imply that they have shared memory.[COLOR="Silver"]

  16. The Following 2 Users Say Thank You to priya456 For This Useful Post:

    lwigfulltiffany (March 27th, 2019), srgisjeff (March 26th, 2019)

  17. #9
    Member
    Join Date
    Sep 2018
    Posts
    32
    Thanks
    0
    Thanked 9 Times in 6 Posts

    Default Re: Process and Multi-threading

    Process
    Processes are heavyweight operations
    Each process has its own memory space
    Inter-process communication is slow as processes have different memory addresses
    Context switching between processes is more expensive
    Processes don’t share memory with other processes

    Thread
    Threads are lighter weight operations
    Inter-thread communication can be faster than inter-process communication because threads of the same process share memory with the process they belong to
    Context switching between threads of the same process is less expensive
    Threads share memory with other threads of the same process

    --- Update ---

    Process
    Processes are heavyweight operations
    Each process has its own memory space
    Inter-process communication is slow as processes have different memory addresses
    Context switching between processes is more expensive
    Processes don’t share memory with other processes

    Thread
    Threads are lighter weight operations
    Inter-thread communication can be faster than inter-process communication because threads of the same process share memory with the process they belong to
    Context switching between threads of the same process is less expensive
    Threads share memory with other threads of the same process

  18. The Following 2 Users Say Thank You to meenal For This Useful Post:

    lwigfulltiffany (March 27th, 2019), srgisjeff (March 26th, 2019)

  19. #10
    Member
    Join Date
    Sep 2018
    Posts
    32
    Thanks
    0
    Thanked 9 Times in 6 Posts

    Default Re: Process and Multi-threading

    The primary difference is that threads within the same process run in a shared memory space, while processes run in separate memory spaces.
    Threads are not independent of one another like processes are, and as a result threads share with other threads their code section, data section, and OS resources (like open files and signals). But, like process, a thread has its own program counter (PC), register set, and stack space.
    Advantages of Thread over Process
    1. Responsiveness: If the process is divided into multiple threads, if one thread completes its execution, then its output can be immediately returned.

    2. Faster context switch: Context switch time between threads is lower compared to process context switch. Process context switching requires more overhead from the CPU.

    3. Effective utilization of multiprocessor system: If we have multiple threads in a single process, then we can schedule multiple threads on multiple processor. This will make process execution faster.

    4. Resource sharing: Resources like code, data, and files can be shared among all threads within a process.
    Note: stack and registers can’t be shared among the threads. Each thread has its own stack and registers.

    5. Communication: Communication between multiple threads is easier, as the threads shares common address space. while in process we have to follow some specific communication technique for communication between two process.

  20. The Following 2 Users Say Thank You to meenal For This Useful Post:

    lwigfulltiffany (March 27th, 2019), srgisjeff (March 26th, 2019)

  21. #11
    Member
    Join Date
    Dec 2013
    Location
    Honolulu
    Posts
    83
    Thanks
    1
    Thanked 4 Times in 2 Posts

    Default Re: Process and Multi-threading

    5. Communication: Communication between multiple threads is easier, as the threads shares common address space. while in process we have to follow some specific communication technique for communication between two process.

    This is a good point to make. The network thread has to communicate with that person's thread to actually know what it is doing. They will be sharing files across the internet to actually make this happen. Stop watch work. That common address space can be a buffer on their computer or it can take place on your computer. It does not matter. The point to all of this is that each thread is in sinc with each other over the internet.

  22. The Following 2 Users Say Thank You to planetHollywood For This Useful Post:

    lwigfulltiffany (March 27th, 2019), srgisjeff (March 26th, 2019)

  23. #12
    Member
    Join Date
    Dec 2013
    Location
    Honolulu
    Posts
    83
    Thanks
    1
    Thanked 4 Times in 2 Posts

    Default Re: Process and Multi-threading

    5. Communication: Communication between multiple threads is easier, as the threads shares common address space. while in process we have to follow some specific communication technique for communication between two process.

    This is a good point to make. The network thread has to communicate with that person's thread to actually know what it is doing. They will be sharing files across the internet to actually make this happen. Stop watch work. That common address space can be a buffer on their computer or it can take place on your computer. It does not matter. The point to all of this is that each thread is in sinc with each other over the internet.

  24. The Following 2 Users Say Thank You to planetHollywood For This Useful Post:

    lwigfulltiffany (March 27th, 2019), srgisjeff (March 26th, 2019)

  25. #13

    Default Re: Process and Multi-threading

    process is nothing but executing program...one or more threads executing same time ....is called multi threading .operating system allocates processeser time....
    Last edited by Muneera123; February 6th, 2019 at 01:33 AM.

  26. The Following 2 Users Say Thank You to Muneera123 For This Useful Post:

    lwigfulltiffany (March 27th, 2019), srgisjeff (March 26th, 2019)

  27. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Process and Multi-threading

    Old thread closed
    If you don't understand my answer, don't ignore it, ask a question.

  28. The Following 2 Users Say Thank You to Norm For This Useful Post:

    lwigfulltiffany (March 27th, 2019), srgisjeff (March 26th, 2019)

Similar Threads

  1. java multi threading
    By srkmca07@gmail.com in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 24th, 2013, 10:03 AM
  2. adding 2 random numbers using multi threading
    By namso1902 in forum Threads
    Replies: 1
    Last Post: August 13th, 2013, 01:46 PM
  3. Replies: 12
    Last Post: May 1st, 2013, 02:55 PM
  4. Replies: 7
    Last Post: April 27th, 2013, 07:15 AM
  5. InterruptedException in multi threading
    By me_shankara in forum Threads
    Replies: 1
    Last Post: April 18th, 2013, 12:54 PM