LinkedBlockingQueue linkedBlockingQueue = new LinkedBlockingQueue(); ThreadPoolExecutor pool = new ThreadPoolExecutor(10, 15, 10, TimeUnit.SECONDS, linkedBlockingQueue); Runnable runnable = new Runnable() { @Override public void run() { Jedis jedis = new Jedis("localhost"); try { Thread.sleep(5000); System.out.println(Thread.currentThread().getName() + "正在执行。。。"); jedis.lpush(++w+"", new Date()+""); //list //jedis.sadd("sets", "element001") set // jedis.zadd("zset", 7.0, "element001")); zset //jedis.hset("hashs", "key001", "value001"); //hash jedis.hkeys("hashs") } catch (Exception e) { e.printStackTrace(); } } }; Jedis jedis = new Jedis("localhost"); while(true){ Thread t1 = new Thread(runnable); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } pool.execute(t1); System.out.println(jedis.lpop(w+""));
用线程池从redis中取出数据
最新推荐文章于 2025-10-13 11:20:50 发布
本文介绍了一种使用Java中的Jedis客户端库结合线程池来执行Redis数据库操作的方法。通过创建一个固定的线程池并利用LinkedBlockingQueue作为任务队列,实现了对Redis的高效列表操作。此外,还展示了如何通过继承Runnable接口来定义执行这些操作的具体任务。
168

被折叠的 条评论
为什么被折叠?



