202003字节跳动面经

1. 一二面,视频,耗时120分钟

1.1 面试题

  1. master离线任务调度中心相关改造,子节点监听父节点任务,改成基于zk队列?如果zk挂掉了怎么办?

  2. 平台任务状态和yarn上任务状态的统一?

  3. consumer 组内rebalance的过程?

  4. Kafka为什么不把所有的数据都落到一个partition内?

  5. Kafka的磁盘存储是怎么做的?

  6. Kafka的网络线程模型?

  7. Flink的背压机制,如何排查背压问题?
    参考:
    如何分析及处理Flink反压

  8. Flink号称是Exactly-Once,是如何做到的?
    参考:
    一文搞懂Flink的Exactly Once和At Least Once
    Flink Checkpoint问题排查实用指南
    Apache Flink管理大型状态之增量Checkpoint详解
    谈谈流计算中的Exactly Once特性

  9. Flink的State管理?使用RocksDB会不会有内存溢出的问题?
    参考:
    State Processor API:如何读取,写入和修改Flink应用程序的状态

    扫描二维码关注公众号,回复: 11166780 查看本文章
  10. Flink的内存管理?
    参考:
    Flink原理与实现:内存管理

  11. 做过哪些JVM调优?GC中CMS和G1的区别?

  12. Java中的各种锁及其使用场景?

1.2 编程题

  • 线程交替打印,线程一打印[1,2,3,4],线程二打印[a,b,c,d]
/**
 * @author :zyt
 * @date :Created in 2020/3/24 8:42 PM
 * @description: 线程交替打印ABC 使用lock的condition
 * @modified By:
 * @version: 1.0.0
 */
public class ThreadInTurnPrint {
    private static Lock lock = new ReentrantLock();
    private static Condition A = lock.newCondition();
    private static Condition B = lock.newCondition();
    private static Condition C = lock.newCondition();

    private static int count = 0;


    static class ThreadA extends Thread{
        @Override
        public void run() {
            try {
                lock.lock();
                System.out.println("A加锁");
                for (int i = 0; i < 2; i++) {
                    System.out.println("A");
                System.out.println(count);
                count++;
                while (count%3 != 0){
                    System.out.println("A等待");
                    A.await();
                }
                B.signal();
                }
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }
    }

    static class ThreadB extends Thread{
        @Override
        public void run() {
            try {
                lock.lock();
                System.out.println("B加锁");
                for (int i = 0; i < 1; i++) {
                    System.out.println("B");
                System.out.println(count);
                count++;
                while (count%3 != 1){
                    System.out.println("B等待");
                    B.await();
                }
                C.signal();
                }
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }
    }

    static class ThreadC extends Thread{
        @Override
        public void run() {
            try {
                lock.lock();
                System.out.println("C加锁");

                for (int i = 0; i < 1; i++) {
                    System.out.println("C");
                System.out.println(count);
                count++;
                while (count%3 != 2){
                    System.out.println("C等待");
                    C.await();
                }
                A.signal();
                }
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        new ThreadA().start();
        new ThreadB().start();
        new ThreadC().start();
    }
}
  • 写出线程死锁的例子
    两个线程,两个资源,模拟互相等待的场景
public class TestThread {
    public static void main(String[] args) {
        //test dead lock
        Thread t9 = new Thread(new DeadLock(true));
        Thread t10 = new Thread(new DeadLock(false));
        t9.start();
        t10.start();

    }
}

class DeadLock implements Runnable{

    boolean lockFormer;
    static Object o1 = new Object();
    static Object o2 = new Object();

    DeadLock (boolean lockFormer){
        this.lockFormer = lockFormer;
    }

    @Override
    public void run() {
        if(this.lockFormer){
            synchronized (o1) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (o2) {
                    System.out.println("1ok");
                }
            }
        }else{
            synchronized (o2) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (o1) {
                    System.out.println("1ok");
                }
            }
        }
    }
}

在这里插入图片描述

2. 三面,视频,耗时37分钟

2.1 编程题

  • 按行层级打印二叉树
import java.util.*;


/*
public class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;

    }

}
*/
public class Solution {
    ArrayList<ArrayList<Integer> > Print(TreeNode pRoot) {
     ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
		 if(pRoot == null){
			 return result;
		 }
		 
		 Queue<TreeNode> queue = new LinkedList<TreeNode>();
		 ArrayList<Integer> queueList = new ArrayList<Integer>();
		 queue.add(pRoot);
		 int start = 0 ,end = 1;
 
		 while(!queue.isEmpty()){
			 TreeNode current = queue.remove();
			 queueList.add(current.val);
			 start++;
			 if(current.left!=null){
				 queue.add(current.left);
			 }
			 if(current.right!=null){
				 queue.add(current.right);
			 }
			 if(start == end){
				 end = queue.size();
				 start=0;
				 result.add(queueList);
				 queueList = new ArrayList<Integer>();
			 }
			 
		 }
		 return result;
    }   
}
原创文章 25 获赞 22 访问量 1250

猜你喜欢

转载自blog.csdn.net/a1240466196/article/details/105450614