Home

Spring声明式缓存动态cacheNames

代码实例 动态指定指定缓存name package com.oliverclio.dms.config.redis; import com.oliverclio.dms.manager.DmsCommonManager; import lombok.AllArgsConstructor; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.cache.interceptor.CacheOperationInvocationContext; import org.springfra...

Read more

Spring Caching KeyGenerator配置

代码实例 指定缓存key的生成策略 设置默认KeyGenerator @Configuration public class RedisConfig extends CachingConfigurerSupport { @Override public KeyGenerator keyGenerator() { return new SimpleKeyGenerator() { @Override @NonNull public Object generate(@NonNull Object target, @NonNull Method m...

Read more

Spring声明式缓存整合Redis

安装Redis Redis在Docker下的安装 依赖配置 基于Spring Boot项目 Spring Boot项目起步配置 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <!-- Lettuce使用连接池时需要添加依赖 --> <dependency> <groupId>org.apache.commons</g...

Read more

logback使用

自定义配置 总体结构 使用<appender>元素定义输出端,其中<encoder>指定输出样式,<filter>指定过滤规则,带有policy的如<rollingPolicy>则指定输出规则(如输出的日志文件按什么逻辑拆分等) <root>或<logger>元素可指定根logger或某个指定logger的输出端、输出的日志等级、是否继续传递给上级logger处理等。 代码实例 src/main/resources/logback-spring.xml <?xml version="1.0" encoding="UTF-8"?> <configuration> ...

Read more

Maven阿里云镜像配置

配置例子 修改setting.conf <mirrors> <mirror> <id>nexus-aliyun</id> <mirrorOf>central</mirrorOf> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> </mirror> </mirrors>

Read more

Maven JDK版本配置

配置例子 修改setting.conf <profiles> <profile> <id>jdk-1.8</id> <activation> <activeByDefault>true></activeByDefault> <jdk>1.8</jdk> </activation> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compile...

Read more

Java线程状态转换

线程状态 new,线程尚未启动 runnable,线程正被JVM执行,但线程可能在等待来自操作系统的资源,例如CPU、I/O blocked,线程正等待监视器锁,以进入或再次进入(从条件队列中被唤醒)同步块或同步方法 waiting,线程正等待另一条线程满足其等待的条件并唤醒它 timed wating,线程正等待另一条线程在一定时间内满足其等待的条件并唤醒它,或者正单纯等待一定时间 terminated,线程执行完成 线程状态转换 调用Thread.yield()只是一种对线程调度的提示,调度器可能会忽略此提示,并让当前线程继续执行

Read more

Java数组类型以及数组强制转型

知识总结 数组类与其它类一样,是Object的子类 @Test void test() { int[] intArray = new int[5]; System.out.println(Object.class.isAssignableFrom(int[].class)); System.out.println(Object.class.isInstance(int[].class)); System.out.println(intArray instanceof Object); } /* 输出结果 true true true */ @Test void test() { String[] stringArray = new ...

Read more

Java锁的条件队列

概述 在某些情况下,线程成功获取到锁后发现仍需等待某些条件才能继续往下执行,这时该线程可以把锁释放并进入条件队列,等待持有该锁的其它线程使等待的条件满足,并再次唤醒在条件队列中的线程,被唤醒的线程会再次参与锁的竞争 监视器锁的条件队列 一个监视器锁只有一个条件队列 核心方法 object.wait() 当前线程把锁释放并进入条件队列 object.notify() 唤醒条件队列中的任意一条线程 object.notifyAll() 唤醒条件队列中的所有线程 例子 public class BoundedBuffer<V> { private final V[] buf; private int tail; private...

Read more

Redis基本命令

key操作 # 查询所有key keys * # 判断key是否存在 exists k1 # 查看值类型 type k1 # 删除key del k1 # 异步删除key unlink k1 # 设置过期时间,默认单位秒 expire k1 10 # 查看key剩余存活时间,-1永不过期,-2已过期 ttl k1 数据库操作 # 切换数据库 select 0 # 查看当前库的key数 disize # 清空当前库 flushdb # 清空所有库 flushall 字符串操作 # 设置值 set k1 v1 # 获取值 get k1 # 字符串追加 append k1 abc # 获取字符串长度 strlen k1 # 值不存在则设置值 setnx...

Read more