多进程(1)
多线程 1.认识线程 1.1概念 进程是系统分配资源的最小单位 线程是系统调度的最小单位 一个进程内的线程之间是可以共享资源的 每个进程内至少有一个线程存在,即主线程 进程和线程的区别? 1.进程是系统分配资源的最小单位 2.线程是系统调度的最小单位 3.一个进程中的各个线程之间共享 方法区(常量池)、堆 线程也存在并发、并行 代码1: public static void main ( String [ ] args ) throws InterruptedException { Thread . sleep ( 9999999 L ) ; } 使用 jconsole 命令观察线程 代码2: public static void main ( String [ ] args ) throws InterruptedException { new Thread ( new Runnable ( ) { @Override public void run ( ) { try { Thread . sleep ( 9999999 L ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } } } ) . start ( ) ; } 使用 jconsole 命令观察线程 代码1的线程名字是 main