博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
单例模式的线程安全
阅读量:7153 次
发布时间:2019-06-29

本文共 894 字,大约阅读时间需要 2 分钟。

package com.day3;public class SingleTonDemo {   public static void main(String[] args) {       SinleTonThread sinleTonThread=new SinleTonThread();       Thread thread=new Thread(sinleTonThread);       thread.start();       Thread thread2=new Thread(sinleTonThread);       thread2.start();}}class SinleTonThread  implements Runnable{    @Override    public void run() {        SingleTon.getinstance();            }    }class SingleTon{    private static SingleTon singleTon=null;    private SingleTon() {        System.out.println("单例模式");    }    public static SingleTon getinstance(){        if(singleTon==null) {            synchronized (SingleTon.class) {                if(singleTon==null) {                    singleTon=new SingleTon();                }            }            }                        return singleTon;            }}

 

转载于:https://www.cnblogs.com/tanlei-sxs/p/10023985.html

你可能感兴趣的文章
下半部和推后执行的工作
查看>>
Python简单的用户交互
查看>>
第一天开技术博客
查看>>
Hibernate实现有两种配置,xml配置与注释配置
查看>>
学以致用十三-----Centos7.2+python3+YouCompleteMe成功历程
查看>>
Crossbuild: with crosstool-ng
查看>>
json和xml的区别和优劣
查看>>
nginx.conf
查看>>
在 VSCode 调试过程中,使用 Watcher,免手动重新编译
查看>>
JSON总结
查看>>
【个人作业】单词统计
查看>>
C# 绘制矩形(绘制正方形)
查看>>
矿产资源储量动态监管服务
查看>>
TSM 文件备份到 disk
查看>>
php的一些小细节
查看>>
Beta 冲刺报告模板
查看>>
docker客户端安装
查看>>
Ural(Timus) 1009 K-based Numbers
查看>>
debian下mysql主从配置
查看>>
block 的细节和本质
查看>>