网站建设营销策划书,wordpress.重装,为女朋友做的网站,中贤建设集团网站两个线程#xff0c;相互改变了对方结束条件#xff0c;导致两个线程不能结束。执行时间也都是一样#xff0c;导致两个线程永远不会结束。
Slf4j
public class LiveLockDemo {static volatile int count 10;public static void main(String[] args) {new Thread(() -…两个线程相互改变了对方结束条件导致两个线程不能结束。执行时间也都是一样导致两个线程永远不会结束。
Slf4j
public class LiveLockDemo {static volatile int count 10;public static void main(String[] args) {new Thread(() - {while (count 0) {try {Thread.sleep(500);} catch (InterruptedException e) {e.printStackTrace();}count --;log.info(count{}, count);}}, t1).start();new Thread(() - {while (count 20) {try {Thread.sleep(500);} catch (InterruptedException e) {e.printStackTrace();}count ;log.info(count{}, count);}}, t2).start();}
}
解决办法将执行时间设置成不一样即可。
扩充饥饿锁表示某一个线程长时间获取不到cpu的资源得不到执行。