Big data-java Foundation-8day
Process
-
1. Processes are isolated in memory (memory is not shared).
two。 Communication between processes is through socket, which is also needed on the same computer.
Thread
-
1. A block of code that executes concurrently during program execution.
two。 Memory is shared between threads.
3. A process must have at least one thread (the main thread).
4.Thread: thread class.
Start (); / / notifies cpu that you can start executing the thread.
The block of code that the run (); / / thread actually executes. The method has no return value and no parameters.
Thread t = new Thread (); / / create a thread.
T.start (); / / run.
5.Thread.currentThread (); gets the currently executing thread.
6.yield (); / / waive the preemption right of cpu
7.sleep (int mils) / / hibernates the current thread for the specified number of milliseconds.
8.join (); / / wait for the specified thread to finish
9.Thread.setDaemon (true); / / daemon thread. Must be set before the thread starts.
10.synchronozed (lock) {.} / / synchronize the code block.
Producers and consumers
Notify: randomly notifies a thread in the waiting queue.
NotifyAll: notifies all threads in the waiting queue.