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 10 of 10

Thread: Process and Multi-threading

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 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. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 688 Times in 675 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.

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

    Default Re: Process and Multi-threading

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

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

    Default Re: Process and Multi-threading

    What's your question? How can we help?

  5. #5
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 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

  6. #6
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 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

  7. #7
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 688 Times in 675 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.

  8. #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"]

  9. #9
    Member
    Join Date
    Sep 2018
    Posts
    32
    Thanks
    0
    Thanked 2 Times in 2 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

  10. #10
    Member
    Join Date
    Sep 2018
    Posts
    32
    Thanks
    0
    Thanked 2 Times in 2 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.

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, 02:46 PM
  3. Replies: 12
    Last Post: May 1st, 2013, 03:55 PM
  4. Replies: 7
    Last Post: April 27th, 2013, 08:15 AM
  5. InterruptedException in multi threading
    By me_shankara in forum Threads
    Replies: 1
    Last Post: April 18th, 2013, 01:54 PM