wordpress WebStorm Linxu磁盘 莱斯分布 image art神经网络 arduino程序 arraylist删除指定元素 winbox使用教程 maya曲线建模 python功能 python在线教程 python命令 python的lambda函数 eclipse安装python java安装 linux文档 bcdautofix 一件换肤 海妖花粉哪里多 collect 博途v14安装教程 sdm439 骰子gif 什么是人肉搜索 加速软件 sqlprompt 梦想世界科举答案 c语言小游戏代码 人脸识别代码 豌豆代理 pandas中文手册 骰子技巧 红客是什么 电视应用安装器 打印机故障解析与维修 ps做表格 立即执行函数 java字符串拼接 小程序授权登录
当前位置: 首页 > 学习教程  > 编程语言

脏读,redis分布式锁报错

2021/1/28 22:39:06 文章标签:

报错。这个一会再说 021-01-28 20:42:32.227 [MyScheduler_Worker-3] [1;31mERROR[0;39m [36morg.quartz.core.ErrorLogger:2401[0;39m - Job (DEFAULT.org.jeecg.modules.arrive.job.ArriveTestJob threw an exception. org.quartz.SchedulerException: Job threw an unhandl…

报错。这个一会再说

021-01-28 20:42:32.227 [MyScheduler_Worker-3] [1;31mERROR[0;39m [36morg.quartz.core.ErrorLogger:2401[0;39m - Job (DEFAULT.org.jeecg.modules.arrive.job.ArriveTestJob threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception.
	at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: java.lang.IllegalStateException: failed to create a child event loop
	at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:88)
	at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:58)
	at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:47)
	at io.netty.channel.MultithreadEventLoopGroup.<init>(MultithreadEventLoopGroup.java:59)
	at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:77)
	at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:72)
	at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:59)
	at org.redisson.connection.MasterSlaveConnectionManager.<init>(MasterSlaveConnectionManager.java:187)
	at org.redisson.connection.MasterSlaveConnectionManager.<init>(MasterSlaveConnectionManager.java:156)
	at org.redisson.connection.SingleConnectionManager.<init>(SingleConnectionManager.java:34)
	at org.redisson.config.ConfigSupport.createConnectionManager(ConfigSupport.java:192)
	at org.redisson.Redisson.<init>(Redisson.java:122)
	at org.redisson.Redisson.create(Redisson.java:161)
	at org.jeecg.modules.arrive.job.ArriveTestJob.getClient(ArriveTestJob.java:138)
	at org.jeecg.modules.arrive.job.ArriveTestJob.execute(ArriveTestJob.java:47)
	at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
	... 1 common frames omitted
Caused by: io.netty.channel.ChannelException: failed to open a new selector
	at io.netty.channel.nio.NioEventLoop.openSelector(NioEventLoop.java:169)
	at io.netty.channel.nio.NioEventLoop.<init>(NioEventLoop.java:143)
	at io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:127)
	at io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:36)
	at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:84)
	... 16 common frames omitted
Caused by: java.io.IOException: Too many open files
	at sun.nio.ch.IOUtil.makePipe(Native Method)
	at sun.nio.ch.EPollSelectorImpl.<init>(EPollSelectorImpl.java:65)
	at sun.nio.ch.EPollSelectorProvider.openSelector(EPollSelectorProvider.java:36)
	at io.netty.channel.nio.NioEventLoop.openSelector(NioEventLoop.java:167)
	... 20 common frames omitted

 最近在用jeecg-boot 定时任务的时候,时间间隔短,所以会出现在上条数据还没更新完,又开始查询,所以会出现推送两个条,或者多条一样的数据

所以就想用锁把当前的数据更新完,再进行查询

1.pom.xml引入redis锁

<!-- reids锁 -->
		<dependency>
			<groupId>org.redisson</groupId>
			<artifactId>redisson</artifactId>
			<version>3.8.2</version>
		</dependency>

2.写静态方法

public static RedissonClient getClient() {

        Config config = new Config();

        config.useSingleServer().setAddress("redis://127.0.0.1:6380");

        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }

3.包裹住业务

RedissonClient redisson = PoOrderTestJob.getRedisSing();
        RLock lock = redisson.getLock("PoOrderTestJobLock");
        // 1. 尝试加锁,最多等待10秒,上锁以后10秒自动解锁
        try {

            boolean res = lock.tryLock(10, 30, TimeUnit.SECONDS);
            if (res) {//成功
                //处理业务
             }
        } catch (Exception e) {
            log.info("", e);
        } finally {
            lock.unlock();
        }

4.然后运行一会出先上面的错误

解决方法:不去每次都new,而是不会null,就去调用原来的。

private static RedissonClient redisson=null;

    public static synchronized RedissonClient getRedisSing(){
        if(redisson==null){
            Config config = new Config();

            config.useSingleServer().setAddress("redis://127.0.0.1:6380");
            redisson = Redisson.create(config);
        }

        return redisson;
    }

避免创建太多的redis从而出现上面的报错


本文链接: http://www.dtmao.cc/news_show_650041.shtml

附件下载

相关教程

    暂无相关的数据...

共有条评论 网友评论

验证码: 看不清楚?