Java Inter Process communication and Inter Thread communication?

后端 未结 4 1341
遇见更好的自我
遇见更好的自我 2020-12-29 14:56

What is the difference between a Thread and a Process in the Java context? How is inter-Process communication and inter-Thread communication achieved in Java? Please point m

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-29 15:49

    A thread can access memory inside a process, even memory that could be manipulated by another thread within the same process. Since all threads are internal to the same running process, they can communicate more quickly (because they don't need the operating system to referee).

    A process cannot access memory inside another process, although you can communicate between processes through various means like:

    1. Network packages.
    2. Files
    3. Pipes
    4. Shared Memory
    5. Semaphores
    6. Corba messages
    7. RPC calls

    The important thing to remember with process to process communication is that the communication must be managed through the operating system, and like all things which require a middle man, that adds overhead.

    On the downside, if a thread misbehaves, it does so within the running process, and odds are high it will be able to take down all the well behaving threads. If a process misbehaves, it can't directly write into the memory of the other processes, and odds are that only the misbehaving process will die.

提交回复
热议问题