测试序列化大小和redis多线程pop

测试java序列化占用多大大小

@Test
    public void testNotifyReceiver() throws IOException {
        String str = "{\"cityId\":3,\"hasPush\":true,\"insTm\":1499741846767,\"isDelete\":0,\"isForceRead\":0,\"isTimeLimit\":0,\"messageImeiType\":0,\"mtype\":0,\"notifyId\":1754929,\"shardx\":511,\"status\":0,\"targetId\":501498,\"targetName\":\"吴英(菜鸟揽件)\",\"targetType\":2}";
        NotifyReceiver notifyReceiver = JSON.parseObject(str,NotifyReceiver.class);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
        objectOutputStream.writeObject(notifyReceiver);
        objectOutputStream.flush();
        System.out.println("testNotifyReceiver:" + byteArrayOutputStream.toByteArray().length);

    }

测试redis多线程pop是否有问题

@Test
    public void testPop() throws InterruptedException {

        notifyCacheService.getsRedisTemplate().executePipelined(new RedisCallback() {
            @Override
            public Object doInRedis(RedisConnection connection) throws DataAccessException {
                for (int i = 0; i< 100000; ++i){
                    connection.lPush("test_redis_pop".getBytes(), String.valueOf(i).getBytes());
                }
                return null;
            }
        });

        AtomicLong total = new AtomicLong(0);
        System.out.println("test start");
        for (int i = 0; i < 30; i++) {
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    long sum = 0;
                    while (true) {
                        String s = notifyCacheService.getsRedisTemplate().opsForList().leftPop("test_redis_pop");
                        if ( s != null) {
                            sum += Integer.valueOf(s);
                        }else{
                            break;
                        }
                    }
                    total.addAndGet(sum);
                }
            });
        }


        executorService.awaitTermination(2, TimeUnit.MINUTES);

        System.out.println("testResult:" + total.get());
    }
 

                            
                        
                    
                    
                    

你可能感兴趣的:(测试序列化大小和redis多线程pop)