1.使用synchronized悲观锁(秋招阿里的一个笔试题,应该写的比较复杂,然后就没有然后了o(╥﹏╥)o) public class ThreadThreadp { private int flag = 0; public synchronized void printa() throws InterruptedException { while (true) { if(flag ==0) { System.out.print("A"); flag = 1; notifyAll(
一.守护进程 主进程创建守护进程 守护进程其实就是'子进程' 一.守护进程内无法在开启子进程,否则会报错二.进程之间代码是相互独立的,主进程代码运行完毕,守护进程也会随机结束 守护进程简单实例: from multiprocessing import Process import time def task(name): #此时的task为守护进程 print('%s is running' % name) #该行并不会被打印,因为主进程结束,守护进程会随之结束 time.sleep(3) if