t02_問題

六个小豹發表於2024-03-11

多執行緒

@Resource
    private RedisIdWorker redisIdWorker;
    private ExecutorService ex= Executors.newFixedThreadPool(500);
    @Test
    void testIdWorker()throws InterruptedException{
        CountDownLatch latch=new CountDownLatch(300);
        Runnable task=()->{
            for(int i =0;i<100;i++){
                long id=redisIdWorker.nextId("order");
                System.out.println("id="+id);
            }
            latch.countDown();
        };
        long begin=System.currentTimeMillis() ;
        for (int i = 0; i < 300; i++) {
            ex.submit(task);
        }
        latch.await();
        long end=System.currentTimeMillis() ;
        System.out.println("time="+(end-begin));
    }
List<UserDTO> userDTOS=userService.query().in("id",ids).last("ORDER BY FIELD (id,"+idStr+")").list()
        .stream()
        .map(user -> BeanUtil.copyProperties(user,UserDTO.class))
        .collect(Collectors.toList());