Redis工具类

2023-11-18

public class RdsUtils {

    @Resource
    private static RedisTemplate redisTemplate;


    /**
     * 设置键值对
     *
     * @param key   键
     * @param value 值
     * @return
     */
    public static Boolean set(String key, String value) {
        try {
            redisTemplate.opsForValue().set(key,value);
            return true;
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return false;
    }


    /**
     * 设置键值对,并给键设置过期时间
     *
     * @param key   键
     * @param value 值
     * @param time  过期时间(单位:秒)
     * @return
     */
    public static Boolean setex(String key, String value, int time) {
        try {
            if(time <= 0 ){
                set(key,value);
            }else{
                redisTemplate.opsForValue().set(key,value,time, TimeUnit.SECONDS);
            }
            return true;
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return false;
    }


    /**
     * 设置键值对, 如果键已存在则设置失败
     *
     * @param key   键
     * @param value 值
     * @return
     */
    public static Boolean setIfAbsent(String key, String value) {
        try {
            return redisTemplate.opsForValue().setIfAbsent(key,value);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return false;
    }


    /**
     * 通过键获取值
     *
     * @param key 键
     * @return
     */
    public static String get(String key) {
        try {
            return (String)redisTemplate.opsForValue().get(key);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 一次性获取多个 key 的 value 值
     *
     * @param keys 键集合
     * @return
     */
    public static List mget(String... keys) {
        try {
            if(keys == null || keys.length == 0){
                return null;
            }
            return redisTemplate.opsForValue().multiGet(Arrays.asList(keys));
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 通过 key 获取 value 的字符数
     *
     * @param key
     * @return
     */
    public static Long strlen(String key) {
        try {
            return redisTemplate.opsForValue().size(key);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return 0L;
    }


    /**
     * 通过 key 获取 value 并截取部分字符串
     * 下标超出范围则返回错误
     *
     * @param key   键
     * @param start 开始下标
     * @param end   结束下标
     * @return
     */
    public static String substr(String key, int start, int end) {
        try {
            String value = get(key);
            if(StringUtils.isEmpty(value)){
                return null;
            }else{
                if(end <= 0){
                    end = value.length();
                }
                return value.substring(start, end);
            }
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 通过 key 获取 value,并用新值覆盖
     * 返回 旧值
     *
     * @param key   键
     * @param value 新值
     * @return
     */
    public static String getset(String key, String value) {
        try {
            return (String)redisTemplate.opsForValue().getAndSet(key, value);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 通过 key 获取 value 并在已有基础上追加内容
     * 如果不存在则创建 value
     *
     * @param key   键
     * @param value 追加内容
     * @return
     */
    public static Integer append(String key, String value) {
        try {
            return redisTemplate.opsForValue().append(key, value);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 通过 key 获取 value 并将 value 当作整数减 1
     *
     * @param key 键
     * @return
     */
    public static Long decr(String key) {
        try {
            return redisTemplate.opsForValue().decrement(key);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return 0L;
    }


    /**
     * 通过 key 获取 value 并将 value 当作整数减去设定值
     *
     * @param key      键
     * @param subValue 设定值
     * @return
     */
    public static Long decr(String key, int subValue) {
        try {
            return redisTemplate.opsForValue().decrement(key,subValue);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return 0L;
    }


    /**
     * 通过 key 获取 value 并将 value 当作整数加 1
     *
     * @param key 键
     * @return
     */
    public static Long incr(String key) {
        try {
            return redisTemplate.opsForValue().increment(key);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return 0L;
    }


    /**
     * 通过 key 获取 value 并将 value 当作整数增加设定值
     *
     * @param key      键
     * @param addValue 增加值
     * @return
     */
    public static Long incr(String key, int addValue) {
        try {
            return redisTemplate.opsForValue().increment(key,addValue);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return 0L;
    }


    /**
     * 通过 key 获取 value 并将 value 当作浮点类型增加设定值
     *
     * @param key      键
     * @param addValue 增加值(浮点类型)
     * @return
     */
    public static Double incrByFloat(String key, float addValue) {
        try {
            return redisTemplate.opsForValue().increment(key,addValue);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 通过 key 删除相关记录
     *
     * @param key 键
     * @return
     */
    public static Boolean del(String key) {
        try {
            return redisTemplate.delete(key);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return false;
    }


    /**
     * 判断指定 key 是否存在(且未过期)
     *
     * @param key 键
     * @return
     */
    public static Boolean exists(String key) {
        try {
            Boolean exist = redisTemplate.hasKey(key);
            if(exist){
                Long expire = redisTemplate.getExpire(key, TimeUnit.SECONDS);
                if(expire == null || expire == 0L){
                    return false;
                }
            }
            return false;
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return false;
    }


    /**
     * 设置指定 key 的相对过期时间
     *
     * @param key    键
     * @param expire 过期时间(单位:秒)
     * @return
     */
    public static Boolean expire(String key, int expire) {
        try {
            return redisTemplate.expire(key, expire, TimeUnit.SECONDS);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return false;
    }


    /**
     * 设置指定 key 的绝对过期时间
     *
     * @param key    键
     * @param date   过期时间
     * @return
     */
    public static Boolean expireat(String key, Date date) {
        try {
            return redisTemplate.expireAt(key, date);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return false;
    }



    /**
     * 移除给 key 设定的过期时间,使得 key 永不过期
     *
     * @param key 键
     * @return
     */
    public static Boolean persist(String key) {
        try {
            return redisTemplate.persist(key);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return false;
    }


    /**
     * 判断 hash 数据类型是否包含指定项
     *
     * @param key   键
     * @param field 字段
     * @return
     */
    public static Boolean hexists(String key, String field) {
        try {
            return redisTemplate.opsForHash().hasKey(key, field);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return false;
    }


    /**
     * 获得 hash 数据类型中的指定项内容
     *
     * @param key   键
     * @param field 字段
     * @return
     */
    public static Object hget(String key, String field) {
        try {
            return redisTemplate.opsForHash().get(key, field);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 获取 hash 数据类型中指定 key 的全部项
     *
     * @param key 键
     * @return
     */
    public static Map hgetAll(String key) {
        try {
            return redisTemplate.opsForHash().entries(key);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 获取 hash 数据类型中的对应项的内容并增加整数值
     *
     * @param key      键
     * @param field    字段
     * @param addValue 增加值
     * @return
     */
    public static Long hincr(String key, String field, int addValue) {
        try {
            return redisTemplate.opsForHash().increment(key, field, addValue);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 获取 hash 类型数据中的对应项的内容增加浮点数值
     *
     * @param key      键
     * @param field    字段
     * @param addValue 增加值
     * @return
     */
    public static Double hincrByDouble(String key, String field, float addValue) {
        try {
            return redisTemplate.opsForHash().increment(key, field, addValue);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 获取 hash 数据类型中指定 key 的所有 field 值
     *
     * @param key 键
     * @return
     */
    public static List hkeys(String key) {
        try {
            return redisTemplate.opsForHash().values(key);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 获取 hash 数据类型中指定 key 的 field 数量
     *
     * @param key 键
     * @return
     */
    public static Long hlen(String key) {
        try {
           return redisTemplate.opsForHash().size(key);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return 0L;
    }


    /**
     * 获取 hash 数据类型中指定 key 和多个 filed 的所有内容
     *
     * @param key    键
     * @param fields 字段集合
     * @return
     */
    public static List hmget(String key, String... fields) {
        try {
            return redisTemplate.opsForHash().multiGet(key, Arrays.asList(fields));
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 通过 key filed 新增 hash 数据类型数据
     * 如果指定项不存在则新建,已存在则覆盖。
     *
     * @param key   键
     * @param field 字段
     * @param value 值
     * @return
     */
    public static Boolean hset(String key, String field, String value) {
        try {
            redisTemplate.opsForHash().put(key,field,value);
            return true;
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return false;
    }


    /**
     * 通过 key filed 设置 hash 数据类型数据
     * 如果该项已存在则执行失败
     *
     * @param key   键
     * @param field 字段
     * @return
     */
    public static Boolean hsetIfAbsent(String key, String field, String value) {
        try {
            return redisTemplate.opsForHash().putIfAbsent(key, field, value);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return false;
    }


    /**
     * 获取 hash 数据类型指定 key 所有 value
     *
     * @param key 键
     * @return
     */
    public static List hvals(String key) {
        try {
            return redisTemplate.opsForHash().values(key);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 通过 key 获取 list 数据类型的列表长度
     *
     * @param key 键
     * @return
     */
    public static Long llen(String key) {
        try {
            return redisTemplate.opsForList().size(key);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return 0L;
    }


    /**
     * 通过 key 弹出指定 list 列表的头部项
     *
     * @param key 键
     * @return
     */
    public static Object lpop(String key) {
        try {
            return redisTemplate.opsForList().leftPop(key);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 通过 key 弹出指定 list 列表的尾部项
     *
     * @param key 键
     * @return
     */
    public static Object rpop(String key) {
        try {
            return redisTemplate.opsForList().rightPop(key);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 通过 key 在指定的 list 列表头部添加 1项
     *
     * @param key   键
     * @param value 值
     * @return
     */
    public static Long lpush(String key, String value) {
        try {
            return redisTemplate.opsForList().leftPush(key,value);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 通过 key 在指定的 list 列表尾部添加 1项
     *
     * @param key
     * @param value 值
     * @return
     */
    public static Long rpush(String key, String value) {
        try {
            return redisTemplate.opsForList().rightPush(key,value);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 通过 key 在指定的 list 列表头部添加 1 项
     * 列表不存在时操作无效
     *
     * @param key   键
     * @param value 值
     * @return
     */
    public static Long lpushx(String key, String value) {
        try {
            return redisTemplate.opsForList().leftPushIfPresent(key, value);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 通过 key 在指定的 list 列表头尾部添加 1 项
     * 如果列表不存在,操作无效
     *
     * @param key   键
     * @param value 值
     * @return
     */
    public static Long rpushx(String key, String value) {
        try {
            return redisTemplate.opsForList().rightPushIfPresent(key, value);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 通过 key 返回指定 list 列表中的所有数据
     *
     * @param key 键
     * @return
     */
    public static List lrange(String key) {
        try {
            return redisTemplate.opsForList().range(key,0,-1);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 通过 key 指定下标索引范围内的 list 列表
     *
     * @param key   键
     * @param start 开始下标
     * @param end   结束下标
     * @return
     */
    public static List lrange(String key, int start, int end) {
        try {
            return redisTemplate.opsForList().range(key,start,end);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 通过 key 在 list 列表指定位置设置列表项,
     * 如果指定位置超过 list 总长度则执行失败
     *
     * @param key   键
     * @param index 指定位置下标
     * @param value 值
     * @return
     */
    public static Boolean lset(String key, int index, String value) {
        try {
            redisTemplate.opsForList().set(key,index,value);
            return true;
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return false;

    }


    /**
     * 通过 key 指定下标索引范围截取 list 列表
     *
     * @param key   键
     * @param start 开始下标
     * @param end   结束下标
     * @return
     */
    public static Boolean ltrim(String key, int start, int end) {
        try {
            redisTemplate.opsForList().trim(key,start,end);
            return true;
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return false;
    }




    /**
     * 将成员元素加入到集合中,若已经存在则将被忽略
     *
     * @param key   键
     * @param field 字段
     * @return
     */
    public static Boolean saddIfAbstrent(String key, String field) {
        try {
            redisTemplate.opsForSet().add(key,field);
            return true;
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return false;
    }


    /**
     * 通过 key 获取 set 数据类型集合中的元素数量
     *
     * @param key
     * @return
     */
    public static Long scard(String key) {
        try {
            return redisTemplate.opsForSet().size(key);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return 0L;
    }


    /**
     * 通过指定 key 返回给定集合之间的差集
     * 不存在的集合 key 将视为空集
     *
     * @param key1 集合 1 key
     * @param key2 集合 2 key
     * @return
     */
    public static Set sdiff(String key1, String key2) {
        try {
            return redisTemplate.opsForSet().difference(key1, key2);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 返回给定所有给定集合的交集。
     * 不存在的集合 key 被视为空集。
     * 当给定集合当中有一个空集时,结果也为空集(根据集合运算定律)
     *
     * @param key1 集合 1 key
     * @param key2 集合 2 key
     * @return
     */
    public static Set sinter(String key1, String key2) {
        try {
            return redisTemplate.opsForSet().intersect(key1, key2);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 返回给定集合的并集
     * 不存在的集合 key 被视为空集
     *
     * @param key1 集合 1 key
     * @param key2 集合 2 key
     * @param keys 多个集合 key 数组
     * @return
     */
    public static Set sunion(String key1, String key2, String... keys) {
        try {
            return redisTemplate.opsForSet().union(key1, key2);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 将给定集合之间的差集存储在指定的集合中。
     * 如果指定的集合 key 已存在, 则会被覆盖
     *
     * @param key1 指定集合 key
     * @param key2 集合1 key
     * @param key3 集合2 key
     * @return
     */
    public static Long sdiffstore(String key1, String key2, String key3) {
        try {
            return redisTemplate.opsForSet().differenceAndStore(key1, key2,key3);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 将给定集合之间的交集存储在指定的集合中。
     * 如果指定的集合已经存在,则将其覆盖
     *
     * @param key1 指定集合 key
     * @param key2 集合1 key
     * @param key3 集合2 key
     * @return
     */
    public static Long sinterstore(String key1, String key2, String key3) {
        try {
            return redisTemplate.opsForSet().intersectAndStore(key1, key2,key3);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 将给定集合的并集存储在指定的集合中。
     * 如果集合已经存在,则将其覆盖
     *
     * @param key1 指定集合 key
     * @param key2 集合1 key
     * @param key3 集合2 key
     * @return
     */
    public static Long sunionstore(String key1, String key2, String key3) {
        try {
            return redisTemplate.opsForSet().unionAndStore(key1, key2,key3);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }


    /**
     * 通过 key 判断 field 是否是集合内的元素
     *
     * @param key   键
     * @param field 字段
     * @return
     */
    public static Boolean sismember(String key, String field) {
        try {
             return redisTemplate.opsForSet().isMember(key, field);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return false;
    }


    /**
     * 通过 key 获取指定集合中的所有的成员。
     * 不存在的集合将被视为空集合
     *
     * @param key 键
     * @return
     */
    public static Set smembers(String key) {
        try {
            return redisTemplate.opsForSet().members(key);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }




    /**
     * 通过 key 移除集合中为 field 的元素
     * 不存在的成员元素会被忽略
     *
     * @param key   键
     * @param fields 需要移除的元素
     * @return
     */
    public static Long srem(String key, String...fields) {
        try {
            return redisTemplate.opsForSet().remove(key, fields);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }
}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Redis工具类 的相关文章

  • 尝试提取 jar 文件时出错

    我正在尝试使用以下命令提取 jar 文件 C Program Files Java jdk1 7 0 25 bin gt jar xf C Users MyJar jar 但出现错误 java io IOException META INF
  • Emacs 打字骨架对插入也许

    在 Eclipse 中 编辑 Java 代码时 如果我输入一个左括号 我会得到一对括号 如果我然后 输入 第二个括号 它不会插入额外的括号 我如何在 emacs 中得到它 Eclipse 编辑器足够聪明 当我输入闭括号时 它知道我刚刚完成了
  • 如何在 NetBeans 中以调试模式单步执行已实现的方法?

    我有课XImpl java它实现了一个接口X java 以及所有它的方法 我调试项目 在执行流程中遇到一个方法X processSomeValue 现在 当我尝试进入该方法时processSomeValue 我无能为力 有什么办法可以让我进
  • Java 延迟/等待

    如何将 while 循环延迟到 1 秒间隔 而不减慢其运行的整个代码 计算机的速度到一秒延迟 只是一个小循环 Thread sleep 1000 do nothing for 1000 miliseconds 1 second
  • java.io.IOException: EnsureRemaining: 仅剩余 0 个字节,尝试读取 1

    我在 giraph 中的自定义类方面遇到一些问题 我制作了 VertexInput 和 Output 格式 但总是收到以下错误 java io IOException ensureRemaining Only bytes remaining
  • JCombobox 字符串项(可见)和整数键(固有)

    我有一个数据库模式 它将作为 JTable 列显示在 JCombobox 中以选择名称 但我希望将 ID 字段插入 作为外键 到另一个表中 通常 在下拉列表中选择一个项目 将所选项目带到组合框的显示区域 我想要做的是 当选择组合框中的任何项
  • 如何将 Struts 2 与 Velocity 和 Tiles 结合使用

    有人能够获得与 struts 2 一起使用的速度和图块吗 我在网上查找示例或教程时遇到一些问题 从我从邮件列表中收集到的信息来看 这似乎根本不可能 但邮件已经很旧了 https struts apache org docs tiles pl
  • Junit测试中LocalDateTime反序列化的问题

    我有问题LocalDateTime反序列化Junit测试 我有简单的REST API返回一些DTO目的 当我呼叫端点时 响应没有问题 它是正确的 然后我尝试编写单元测试 得到MvcResult并使用ObjectMapper将其转换为我的DT
  • 如何在我的 HttpClient 执行器中遵循单一职责原则?

    我在用RestTemplate http docs spring io spring docs current javadoc api org springframework web client RestTemplate html as
  • 将 Java 3D 坐标转换为 2D 屏幕坐标

    我正在使用一个名为 Walrus 的 Java 3D 应用程序 该应用程序用于显示有向图 该代码已经具有突出显示节点并在给定其屏幕坐标的情况下在图形中相邻绘制标签的功能 旋转屏幕后 该节点不再突出显示 我所拥有的是 3D 中的节点坐标 我需
  • 如何从 Jackson 中的自定义解串器调用默认解串器

    我在杰克逊的自定义解串器有问题 我想访问默认序列化器来填充我要反序列化的对象 在填充之后 我将做一些自定义的事情 但首先我想使用默认的 Jackson 行为反序列化对象 这是我目前拥有的代码 public class UserEventDe
  • IDEA:javac:源版本1.7需要目标版本1.7

    使用 IntelliJ IDEA 运行 JUnit 测试时 我得到 我该如何纠正这个问题 使用SDK 1 7 模块语言级别为1 7 Maven 构建工作正常 这就是为什么我相信IDEA配置问题 您很可能在此处从 Maven 导入了不正确的编
  • 抽象方法实现与抽象方法重写。这两个对于抽象类意味着相同吗?

    我几乎要采取Java SE 8 程序员我 exam 1Z0 808 我正在使用这个学习指南 https www selikoff net java oca 8 programmer i study guide https www selik
  • 获取 n 元组中的所有 1-k 元组

    当 n 5 且 k 3 时 以下循环将执行此操作 List
  • 如何告诉 Eclipse 忽略 Ant build.xml 中的错误?

    我有一个使用 Maven 构建的 Eclipse 项目 并且我在 Eclipse 中使用 m2eclipse 插件来获得 Maven 支持 然而这个项目还包含一个build xml它并不用于实际构建项目 而只是用于编写脚本功能 作为项目开发
  • 在JAVA中将数据写入.txt文件?

    我想知道是否是在JAVA中将计算的数据写入文本文件 我的 JAVA 代码是一个基于 GUI 的 gpa 计算器 我只想添加一个 JButton 和 ActionListener 它将类名 GPA 点和计算出的 GPA 写入 txt 文件 这
  • 使用 Spark SQL 时找不到 Spark Logging 类

    我正在尝试用 Java 进行简单的 Spark SQL 编程 在程序中 我从 Cassandra 表获取数据 将RDD into a Dataset并显示数据 当我运行spark submit命令 我收到错误 java lang Class
  • 正确的单元测试技术

    在使用 TDD 时 我发现自己需要测试一个包含查找值的常量 最终 哈希图 请查看更新中出现这种情况的原因 见下文 private static final Map
  • 如果垃圾收集器没有删除未引用的对象,它们还能运行吗?

    如果一个对象正在等待垃圾收集 但包含一个在该对象的最后一个引用更改时正在运行的线程 那么该线程是否仍会运行并且代码是否仍会执行 那么您是否可能有一堆应该删除的幽灵对象 但它们对您的代码产生了影响 你如何防止这种情况发生 有没有办法让对象知道
  • Swing:如何创建事件并将其分派给组件?

    我需要将一些事件发送到 Swing 中的组件 因此它的处理方式就像任何用户生成的标准 Swing 事件一样 基本上 类似于宏记录器 然后是 JEditorPane 的执行器 但我需要对生成的事件有更多的控制 所以 假设我有一个编辑 我想 捕

随机推荐

  • Caused by: java.lang.NoClassDefFoundError: redis/clients/util/Pool

    严重 Exception sending context initialized event to listener instance of class org springframework web context ContextLoad
  • matlab把数据从胞元类型(cell)转换为矩阵类型(matrix)

    由于经常从txt文件中读取数据 选用textscan函数读取txt文件 读取的数据经常是cell形式的 经常需要转换为mat形式 网上学了两种方式 记录一下 1 strs cellfun str2num cell 2 str char ce
  • 自媒体追热点小技巧,教你快速捕捉最新热点

    追热点创作内容的好处多多 相信自媒体人都亲身体验过 不过 如何快速获取最新热点抢占流量呢 今天 总结了自媒体大神追热点的小技巧 快速捕捉最新热点 1 常规热点 什么叫做常规热点 就是每年必然会发生的热点事件 例如 节日 购物活动 节气 这类
  • 记XVC复盘putty打印TCP:request_sock_tcp:Possible syn flooding on port 2542!Dropping request ! 无法建立连接

    背景 最近因为需要重新做一套XVC的镜像文件 所以拿出来自己写的调试步骤 去复现XVC 问题现象 1 但是当putty中输入xvcServer 之后 vivado连接XVC 2542时 一直打印超时的错误 2 而且putty端一直打印TCP
  • kafka + zookeeper下载/安装/使用(超详细)

    kafka是需要zk来支持 所以先下载zk 1 下载安装zookeeper 下载地址 选择不带source的 下载下来解压2次 进入到 D zookeeper apache zookeeper 3 6 1 bin conf 目录下 把zoo
  • Cadence Gerber文件制作过程

    概述 本人使用Cadence 17 4版本 在这做下笔录 介绍下Gerber文件制作过程 Gerber文件的作用 相信画过板子的人都知道 Layout PCB设计后 需要把资料给制作PCB板厂商 同时也能让自己存档作用 好了 下面只要讲解使
  • 基于Pytorch版本的T2T-ViT+ArcFace的人脸识别训练及效果

    目录 一 前言 二 训练准备 1 T2T ViT的Pytorch版本 2 人脸识别数据和代码架构 3 完整训练代码 三 训练和结果 1 训练 2 结果 一 前言 最近 将transformer在CV领域中新出现的T2T ViT模型修改 再加
  • 我的

    CangLongHead22E5229DEF23ED8E0BF2C55E698486BD0D1C555F1275F5D8BD6553F4A1FEF5EA623255CE7EA69C4D729AA0D76938EF3346260603DB47
  • 两层板PCB如何设计的?

    两层板PCB如何设计的 三层板的PCB又是如何设计的 https blog csdn net qq 42053636 article details 89577815 来自专治PCB疑难杂症总群 四大群群友突破1800人啦 添加杨老师微信号
  • 安卓应用开发入门!Android高级工程师系列学习路线介绍,灵魂拷问

    从基础到架构进阶 包含了腾讯 百度 小米 阿里 乐视 美团 58 猎豹 360 新浪 搜狐等一线互联网公司面试被问到的题目 涵盖了初中高级安卓技术点 文章中所列主要为大纲部分 详细内容可以在文末自行获取哈 如果你熟练掌握本文中列出的知识点
  • Qt 笔记4--Qt 读写CSV

    Qt 笔记4 Qt 读写CSV CSV Comma Separated Values 即逗号分隔值 有时也称为字符分隔值 因为分隔字符也可以不是逗号 其文件以纯文本形式存储表格数据 CSV是一种通用的 相对简单的文件格式 被用户 商业和科学
  • 1067:整数的个数(C C++)

    题目描述 给定k 1
  • 【八股】2023秋招八股复习笔记1(CSBase+部分WXG题)

    文章目录 MYSQL redis 网络 系统 安全 C 招聘要求 x3 部分面经和题目 WXG 后端 x5 MYSQL redis redis memcached mysql 线程模型 6 0多线程 持久化 AOF RDB 功能 过期删除
  • aspx页面添加引用代码

  • Windows远程桌面连接报内部错误

    远程桌面连接出现了内部错误解决方法 1 运行里输入ncpa cpl命令 打开网络连接 2 禁用 启用一下 当前的网卡 3 再通过命令 mstsc 打开远程桌面服务 报错问题解决
  • 基于LabVIEW的音频信号采集分析系统

    本设计基于LabVIEW虚拟仪器开发软件 用PC的声卡与外接麦克风组合采集到外界的声音信息 并保存到WAV文件中 再利用LabVIEW软件进行编程来对采集到的信号进行分析处理 能够显示采集到的波形 滤波后的波形以及其幅度 相位谱和功率谱波形
  • 一个简单的基于epoll的web server

    一个简单的基于epoll的web server 性能还不错我根据一个epoll的模型改了一个http server出来 只有129行 还可以精简不少 呵呵 小测了一下 一秒钟处理了一万了请求 当然这里只是把现成的东西输出 没考虑到发送数据处
  • Qt多国语言动态切换(含源代码)

    Qt中文国际化 含高阶做法 作者 melon 日期 2019 7 15 1 国际化需要用到的工具 lrelease exe lupdate exe linguist exe 非必须 这些工具在Qt5 12 2的bin文件夹都可以找到 lup
  • Hibernate用法:查询,更新,删除!

    一 基本数据查询 使用Hibernate进行数据查询是一件简单的事 Java程序设计人员可以使用对象操作的方式来进行数据查询 查询时使用一种类似SQL的HQL Hibernate Query Language 来设定查询的条件 与SQL不同
  • Redis工具类

    public class RdsUtils Resource private static RedisTemplate redisTemplate 设置键值对 param key 键 param value 值 return public