欢迎光临散文网 会员登陆 & 注册

IO和网络_4月6日

2023-04-06 22:44 作者:搜粪海  | 我要投稿


// 懒汉单例 DCL double check lock

public class MyLazy {

    private static MyLazy myLazy;

    private MyLazy(){

        System.out.println("new MyLazy()");

    }

    public static MyLazy getInstance(){

        if(myLazy == null){

            synchronized (MyLazy.class){

                if(myLazy==null){

                    myLazy = new MyLazy();

                }

            }

        }

        return myLazy;

    }

}


// 饿汉单例

public class MyHungry {

    private final static MyHungry myHungry = new MyHungry(); // final 所以一直指向它,其实也没人修改它的地址

    private MyHungry(){

        System.out.println("new MyHungry()");

    }

    public static MyHungry getInstance(){

        return myHungry;

    }

}


// new Thread 操作

        new Thread() {

            @Override

            public void run() {

                System.out.println("new Thread()");

            }

        }.start();


        new Thread(new Runnable() {

            @Override

            public void run() {

                System.out.println(Thread.currentThread().getName());

                System.out.println("new Thread(new Runnable(){");

            }

        }, "RunnableThread").start();


网络通信不是主机之间,而是进程之间


Client Server

Browser Server


单例模式

饿汉 private get()

懒汉 double check lock 之后再 new


queue.notify();

queue.wait();

queue.remove();


阴影

I shall be your eyes


死亡骑士

I am the Darkness

As you order

At last

For the Lich King

Ride or die


恐惧魔王

Greetings

What is it now?

Agreed

Very well

Die

I hunger


地穴领主

Speak


侍僧

I wish only to serve

Yes, Master


IO和网络_4月6日的评论 (共 条)

分享到微博请遵守国家法律