测试序列化大小和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<Object>() {
            @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());
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容