zoukankan      html  css  js  c++  java
  • ________________死锁

    //简单易懂的死锁程序

    public class Lock implements Runnable {
    Boolean flag;

    public Lock(boolean flag){
    this.flag=flag;
    }
    @Override
    public void run() {
    while(true){


    if(flag)
    {
    synchronized(Mylock.locka){
    yield();
    System.out.println(Thread.currentThread()
    .getName()+"if__________locka");
    synchronized(Mylock.lockb){
    System.out.println(Thread.currentThread()
    .getName()+"if__________lockb");
    }
    }

    }
    else{
    synchronized(Mylock.lockb){
    yield();
    System.out.println(Thread.currentThread()
    .getName()+"else__________locka");
    synchronized(Mylock.locka){
    System.out.println(Thread.currentThread()
    .getName()+"else__________lockb");
    }
    }
    }
    }
    }
    private void yield() {
    // TODO Auto-generated method stub

    }
    static class Mylock{
    public static final Object locka=new Object();
    public static final Object lockb=new Object();
    }
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Lock a=new Lock(false);
    Lock b=new Lock(true);
    Thread t1=new Thread(a);
    Thread t2=new Thread(b);
    t1.start();
    t2.start();

    }

    }

  • 相关阅读:
    HbuildeX项目打包
    百度地图(vue)
    压缩图片
    安卓移动端唤起拨号与邮箱
    上传图片 原生或vant
    git从零开始
    HbuilderX,监视物理按键
    gitlab备份and恢复数据
    ⑨.kubernetes 之ingress
    ⑧.kubernetes pod调度
  • 原文地址:https://www.cnblogs.com/qiqisx/p/7769197.html
Copyright © 2011-2022 走看看