直接上代码
@SpringBootTest
@RunWith(SpringRunner.class)
public class testT {
volatile List<Object> whichs = new ArrayList<>();
@Qualifier("myredis")
@Autowired
private RedisTemplate redis;
@Test
public void HelloWorld() throws InterruptedException {
new Thread(()->{
while (true){
if (this.whichs.size() != 0){
redis.opsForList().leftPushAll("myList",whichs);
this.whichs.removeAll(this.whichs);
}
}
}).start();
new Thread(()->{
while (true){
String one =(String) redis.opsForList().rightPop("myList");
if (one != null){
System.out.println(one);
redis.opsForList().remove("myList",1,one);
}
}
}).start();
String[] message = {"apple","banana","cat","dog"};
this.whichs = Arrays.asList(message);
TimeUnit.SECONDS.sleep(3);
this.whichs.add("abk");
while (Thread.activeCount()>2){
}
}
}