字节一面

发布于 2024-06-28  30 次阅读


问项目

  1. 项目流程
  2. 几个模块具体哪个调用哪个
  3. es是怎么做的
  4. redistoken共享怎么做的,不用redis怎么做
  5. 觉得你项目有哪些难点,说3个
  6. tcp,udp区别,什么时候使用哪个协议
  7. udp要保证消息不丢失怎么办

手撕

一道sql

多线程,一个线程循环读a,如果a是false,另一个线程去修改a,使用notify,wait

public class WaitNotifyExample {
    private boolean state = false;
    private final Object lock = new Object();

    public void threadA() {
        synchronized (lock) {
            while (!state) {
                try {
                    System.out.println("Thread A is waiting.");
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("Thread A is resumed, state is true.");
        }
    }

    public void threadB() {
        synchronized (lock) {
            state = true;
            System.out.println("Thread B changed state to true.");
            lock.notify();
        }
    }

    public static void main(String[] args) {
        WaitNotifyExample example = new WaitNotifyExample();

        Thread a = new Thread(new Runnable() {
            @Override
            public void run() {
                example.threadA();
            }
        });

        Thread b = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    // Ensure Thread A starts and waits before Thread B changes the state.
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                example.threadB();
            }
        });

        a.start();
        b.start();
    }
}
String str1 = "abc";
String str2 = new String("abc");
String str3 = "a" + "b" + "c";
String str4 = "ab";
String str5 = str4 + "c";
//判断
str1 == str2
str1.equals(str2) 
str1 == str3 
str1.equals(str3) 
str1 == str5
str1.equals(str5)

给你一个数组,target,找两个数相加等于target,返回两个下标,没有返回-1,-1

人生の意味は平凡ですか、それとも素晴らしいですか?
最后更新于 2024-07-23