Java
文章平均质量分 55
自我学习
李_杰
这个作者很懒,什么都没留下…
展开
-
Caffeine本地缓存Demo
Gauva和Caffeine的区别 - Gauva基于LRU算法,Caffeine基于W-TinyLFU算法(结合了LRU和LFU的特点) - Caffeine支持异步加载 - Caffeine性能和开销都优于Guava - Caffeine的命中率更高原创 2022-07-03 21:03:09 · 730 阅读 · 1 评论 -
基于guava框架中事件总实现具体事件的监听
文章目录Guava的EventBus可以简化生产/消费模型。EventBus通过非常简单的方式,实现了观察者模式中的监听注册,事件分发。public class GuavaListener { // 只有通过@Subscribe注解的方法才会被注册进EventBus,即可实现对多个消息的订阅 @Subscribe public void receiveMessage(String message) { System.out.println(message);原创 2022-05-31 14:39:41 · 451 阅读 · 0 评论 -
序列化反序列化Demo-jdk、json、protobuf
文章目录demojdk序列化为什么需要serialVersionUID?protobuf使用1、优缺点2、使用步骤各种序列化性能比较常见序列化1、二进制序列化2、文本序列化(可读性好, 性能较差)性能对比空间开销选型建议demopublic static void main(String[] args) throws Exception { /***** jdk begin *****/ File file = new File("D:/saloonCar.out");原创 2022-05-27 22:54:13 · 322 阅读 · 0 评论 -
类加载Demo
文章目录demo1-赋值demo1结果demo1结果分析demo2-执行顺序demo2结果demo2结果分析demo1-赋值public class TestClassLoader { public static TestClassLoader classLoader = new TestClassLoader(); public static int a; public static int b = 0; public static final int c = 2原创 2022-05-14 16:00:35 · 141 阅读 · 0 评论 -
类加载过程
文章目录1、什么是类加载2、类加载的触发时机3、类加载执行过程3.1、加载3.2、验证3.3、准备3.4、解析3.5、初始化4、类加载器的分类和作用4.1、启动类加载器(Bootstrap ClassLoader)4.2、扩展类加载器(Extensions ClassLoader)4.3、应用类(系统)加载器(APP ClassLoader)4.4、自定义类加载器5、双亲委派模型5.1、什么是双亲委派模型5.2、为什么要有双亲委派模型5.3、双亲委派模型能被打破吗?1、什么是类加载就是JVM将描述类的原创 2022-05-14 15:27:00 · 246 阅读 · 0 评论 -
触发Young GC、Full GC的Demo
文章目录1、Young GC1.1、代码1.2、修改参数1.3、运行查看2、Full GC2.1、代码2.2、修改参数2.3、运行查看1、Young GC1.1、代码public class TestYGC { /** 设置参数 -Xms10m 初始化堆内存大小 -Xmx20m 堆最大内存 -Xmn5m 年轻代的大小 -XX:+PrintGCDetails 打印gc明细日志 **/ public static void mai原创 2022-05-07 17:53:08 · 351 阅读 · 0 评论 -
取消一个正在运行中的任务(ThreadPoolExecutor)
文章目录代码结果代码public class TestThreadPoolExecutor2 { public static void main(String[] args) { /**********************************参数begin**********************************/ // 核心线程数 int corePoolSize = 5; // 最大线程数 i原创 2022-04-22 17:47:45 · 947 阅读 · 0 评论 -
构造一个使用特定名称线程的线程池(ThreadPoolExecutor)
文章目录代码结果代码public class TestThreadPoolExecutor { public static void main(String[] args) { /**********************************参数begin**********************************/ // 核心线程数 int corePoolSize = 5; // 最大线程数 in原创 2022-04-20 22:36:56 · 917 阅读 · 0 评论 -
基于阻塞队列实现生产者&消费者模式
文章目录代码代码public class TestProsumer { // 货架可存放商品数量 private Integer goodsShelfSize = 10 ; // 阻塞队列 private ArrayBlockingQueue queue = new ArrayBlockingQueue<Integer>(goodsShelfSize); public static void main(String[] args) {原创 2022-04-17 15:40:23 · 301 阅读 · 0 评论 -
基于CountDownLatch实现多个子任务执行结果汇总
文章目录1、未使用 CountDownLatch结果2、使用 CountDownLatch结果1、未使用 CountDownLatchpublic class TestCountDownLatch { public static void main(String[] args) throws InterruptedException { TestCountDown testCountDown = new TestCountDown(); Thread threa原创 2022-04-15 23:35:50 · 588 阅读 · 0 评论 -
基于原子类实现线程安全的计数器操作
文章目录1、普通变量线程不安全代码结果不符合预期2、AtomicInteger 实现代码结果符合预期1、普通变量线程不安全代码public class TestAtomicInteger { public static int count = 0; public static void main(String[] args) throws InterruptedException { TestCount testCount = new TestCount();原创 2022-04-15 22:26:10 · 399 阅读 · 0 评论 -
死锁Demo
文章目录1、demo2、结果1、demopublic class TestDeadLock { private static String a = "A"; private static String b = "B"; public static void deadLock () { Thread threadA = new Thread(new Runnable() { @Override public void原创 2022-03-31 12:01:10 · 105 阅读 · 0 评论 -
synchronized/ReentrantLock-实现多个线程间的数据同步Demo
文章目录1、未用锁情况2、使用synchronized3、使用ReentrantLock公平锁非公平锁1、未用锁情况demo public static void main(String[] args) { TestTicket testTicket = new TestTicket(); Thread threadA = new Thread(testTicket); Thread threadB = new Thread(testTicke原创 2022-03-31 11:54:50 · 119 阅读 · 0 评论 -
Java多线程(基础、线程安全、线程间通信)
文章目录一、基础1、多线程的优势和问题1. 优势2. 问题2、线程基础1. 启动方式2. Thread核⼼方法3. 扩展:sleep()和wait()的区别4. 线程状态3、线程安全1. 死锁2、synchronized1、synchronized依赖于底层的操作系统的Mutex Lock来实现的, JDK1.6之后做了较大的优化-锁升级机制。2、锁的内存语义3、锁释放和锁获取的内存语义4、synchronized用法5、扩展4、线程间通信1、volatile一、基础1、多线程的优势和问题1. 优势原创 2022-02-25 22:30:58 · 197 阅读 · 0 评论 -
Java语言特性
文章目录前言一、Java的特点1、跨平台性2、面向对象3、安全性4、简单易学5、多线程6、分布式7、高性能8、健壮性二、Java语言的四大特性1、封装2、继承3、多态4、抽象前言自我学习记录一、Java的特点1、跨平台性跨平台性具体表现在于,Java 是“一次编写,到处运行(Write Once,Run any Where)”的语言,因此采用 Java 语言编写的程序具有很好的可移植性,而保证这一点的正是 Java 的虚拟机机制。在引入虚拟机之后,Java 语言在不同的平台上运行不需要重新编译原创 2022-02-25 13:34:55 · 1191 阅读 · 0 评论