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中取出数据
最新推荐文章于 2024-05-10 16:37:35 发布