zoukankan      html  css  js  c++  java
  • oracle db组面试 复习数据库

    很多台DB server, 怎么确保其中一台挂了,里边的东西不会消失? 有多台server做replication
    怎么知道刚刚消失的data在replication的哪边? 用多个pointer指每个server目前data的位址
    很多人要读,偶尔写,要怎么保护? Reader-writer lock
    如果一直不能轮到write怎么处理? 设一个duration,超过没轮到write,就禁止上读锁
    cache用什么机制? lru, lfu
    如果是做影音串流,cache用lru还是lfu好? lfu
    lfu怎么做?

     

     

    implement一个spin lock,
    spin lock自旋锁:表示线程忙的锁

    https://leetcode.com/discuss/interview-question/operating-system/134290/Implement-your-own-spinlock

    public class SpinLock {
        private AtomicBoolean lock;
        
        public SpinLock() {
            lock = new AtomicBoolean(false);
        }
    
        public void lock() {
            while(!tryLock()){};    
        }
    
        public boolean tryLock() {
            return lock.compareAndSet(false, true);
        }
    
        public void unlock() {
            lock.set(true);
        }
    }

     

    实现wait&notify

    看着其实好像挺简单的

    参考:https://howtodoinjava.com/java/multi-threading/wait-notify-and-notifyall-methods/

    wait()

    synchronized( lockObject )
    { 
        while( ! condition )
        { 
            lockObject.wait();
        }
         
        //take the action here;
    }

     

    notify()

    synchronized(lockObject) 
    {
        //establish_the_condition;
     
        lockObject.notify();
         
        //any additional code if needed
    }

    notifyAll()

    synchronized(lockObject) 
    {
        establish_the_condition;
     
        lockObject.notifyAll();
    }

    然后创建Producer Thread,Consumer Thread

     

    使用mutex(其实就是锁吧)

    参考:https://crunchify.com/what-is-java-semaphore-and-mutex-java-concurrency-multithread-explained-with-example/

    public class CrunchifySemaphoreMutexTutorial {
        static Object crunchifyLock = new Object();
        static LinkedList<String> crunchifyList = new LinkedList<String>();
        
        // Semaphore maintains a set of permits.
        // Each acquire blocks if necessary until a permit is available, and then takes it.
        // Each release adds a permit, potentially releasing a blocking acquirer.
        static Semaphore semaphore = new Semaphore(0);
        static Semaphore mutex = new Semaphore(1);
        
        // I'll producing new Integer every time
        static class CrunchifyProducer extends Thread {
            public void run() {
                
                int counter = 1;
                try {
                    while (true) {
                        String threadName = Thread.currentThread().getName() + counter++;
                        
                        mutex.acquire();
                        crunchifyList.add(threadName);
                        System.out.println("Producer is prdoucing new value: " + threadName);
                        mutex.release();
                        
                        // release lock
                        semaphore.release();
                        Thread.sleep(500);
                    }
                } catch (Exception x) {
                    x.printStackTrace();
                }
            }
        }

     

     如何用纯c语言连接mongodb数据库进行读写操作?

    参考:https://docs.mongodb.com/drivers/c/

    #include <mongoc/mongoc.h>
    int
    main (int argc, char *argv[])
    {
       mongoc_database_t *database;
       mongoc_client_t *client;
       mongoc_init ();
       client = mongoc_client_new(
          "mongodb+srv://<username>:<password>@<cluster-url>/test?retryWrites=true&w=majority"
       );
       database = mongoc_client_get_database (client, "test");
       mongoc_database_destroy (database);
       mongoc_client_destroy (client);
       mongoc_cleanup ();
       return 0;
    }

     

     

     
  • 相关阅读:
    centos 配置puTTY rsa自动登录
    Linux LVM 简单操作
    linux 系统下有sda和hda的硬件设备分别代表什么意思
    Centos 安装Sublime text 3
    编译安装MySQL-5.7.13
    药品查询网的数据库
    获得Android设备的唯一序列号
    Android中设置TextView的颜色setTextColor
    介绍几款网页数据抓取软件 分类: 业余 2015-08-07 18:09 5人阅读 评论(0) 收藏
    网上处方药物手册Rxlist 及其药学信息资源 分类: 业余 2015-08-07 14:16 8人阅读 评论(0) 收藏
  • 原文地址:https://www.cnblogs.com/immiao0319/p/14854437.html
Copyright © 2011-2022 走看看