Cider一面二面 2025.12

一面
问项目
限流算法有哪些?
线程安全的List ?
鉴权怎么做的
spring 中涉及到的设计模式有哪些?
多线程编程
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class RpcBatchRequestTest {

    static RpcService rpcService = new RpcService();

    public static void main(String[] args) {
        // rpc 请求参数
        List<Integer> requestIds = IntStream.range(0, 1000).boxed().collect(Collectors.toList());

        // rpc 调用
        List<String> results = batchGetDetails(requestIds);

        // 输出
        for (String result : results) {
            System.out.println(result);
        }
        // 预期输出
        // details 0
        // details 1
        // details 2
        // .......
        // details 999
    }

    /**
     * 某个 rpc service 的接口只提供单个调用
     * 此处需要做一个封装,多次请求后返回
     *
     * 要求按照顺序返回
     *
     * @param ids
     * @return
     */
    public static List<String> batchGetDetails(List<Integer> ids) {
        // 单次调用
        // RpcService rpcService = new RpcService();
        // rpcService.rpcGetDetailsById(1);

        // TODO 在此处实现批量调用

        return null;
    }
}

class RpcService {
    public String rpcGetDetailsById(int id) {
        // 模拟 rpc service 耗时
        try {
            Thread.sleep(20L);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return "details " + id;
    }
}

二面#牛客AI配图神器#
TCP 的可靠性如何保证的?tcp 报文头有哪些内容?
MySQL 三种日志?
看过哪些源码?
分库分表有了解吗?

多线程编程
/*
n个线程交替打印1-100。

比如n=5,输出如下:
第一个线程打印 1
第二个线程打印 2
...
第五个线程打印 5
第一个线程打印 6
第二个线程打印 7
 */
全部评论

相关推荐

评论
2
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务