Tomcat源码:Acceptor与Poller、PollerEvent

news2024/10/7 12:26:59

 参考资料:

《Tomcat源码解析系列(十一)ProtocolHandler》

《Tomcat源码解析系列(十二)NioEndpoint》

前文:

《Tomcat源码:启动类Bootstrap与Catalina的加载》

《Tomcat源码:容器的生命周期管理与事件监听》

《Tomcat源码:StandardServer与StandardService》

《Tomcat源码:Container接口》

《Tomcat源码:StandardEngine、StandardHost、StandardContext、StandardWrapper》

 《Tomcat源码:Pipeline与Valve》

《Tomcat源码:连接器与Executor、Connector》

《Tomcat源码:ProtocolHandler与Endpoint》

前言

        前文中我们介绍到NioEndpoint的start方法启动了Acceptor与Poller这两个异步线程来处理连接请求,本文我们就来接着介绍这两个组件。

目录

前言

一、Acceptor

        1、构造方法

        2、run方法

        countUpOrAwaitConnection

        LimitLatch 

        tryAcquireShared 

        serverSocketAccept

        setSocketOptions

        SocketBufferHandler

        NioChannel

        NioSocketWrapper

二、Poller与PollerEvent

        1、PollerEvent

        2、poller

       register

        createPollerEvent、addEvent

       run

       events

     processKey


一、Acceptor

        在前文的Endpoint的startAcceptorThread方法中,创建了Acceptor对象,并使用异步线程调用了其run方法,下面我们就来介绍下Acceptor对象。

        1、构造方法

        Acceptor的构造方法传入了一个endpoint对象,看过前文的我们知道这里是一个NioEndpoint对象。

public abstract class AbstractEndpoint<S,U> { 
   protected void startAcceptorThread() {
        acceptor = new Acceptor<>(this);
        String threadName = getName() + "-Acceptor";
        acceptor.setThreadName(threadName);
        Thread t = new Thread(acceptor, threadName);
        t.setPriority(getAcceptorThreadPriority());
        t.setDaemon(getDaemon());
        t.start();
    }
}

public class Acceptor<U> implements Runnable {
    private final AbstractEndpoint<?,U> endpoint;
    public Acceptor(AbstractEndpoint<?,U> endpoint) {
        this.endpoint = endpoint;
    }
}

        2、run方法

        由于run方法较长,这里只展示下核心步骤,首先是接收到请求后判断是否已达最大连接数,如果允许则分配SocketChannel,最后进行连接的配置以及处理器的分配。

    @Override
    public void run() {
        int errorDelay = 0;
        long pauseStart = 0;
        try {
            // Loop until we receive a shutdown command
            while (!stopCalled) {
				// ...
                try {
                    //if we have reached max connections, wait
                    endpoint.countUpOrAwaitConnection();
                    U socket = null;
                    try {
                        // Accept the next incoming connection from the server
                        // socket
                        socket = endpoint.serverSocketAccept();
                    } catch (Exception ioe) {
                        // We didn't get a socket
						// ...
                    }
                    // Configure the socket
                    if (!stopCalled && !endpoint.isPaused()) {
                        // setSocketOptions() will hand the socket off to
                        // an appropriate processor if successful
                        if (!endpoint.setSocketOptions(socket)) {
                            endpoint.closeSocket(socket);
                        }
                    } else {
                        endpoint.destroySocket(socket);
                    }
                } catch (Throwable t) {
                    // ...
                }
            }
        } finally {
            stopLatch.countDown();
        }
        state = AcceptorState.ENDED;
    }

        countUpOrAwaitConnection

        countUpOrAwaitConnection是endpoint中的方法,用于判断连接数是否已达最大,这里会获取我们在前文中介绍的endpoint时提及的connectionLimitLatch。

public abstract class AbstractEndpoint<S,U> { 
   private int maxConnections = 8*1024;
   protected void countUpOrAwaitConnection() throws InterruptedException {
        if (maxConnections==-1) {
            return;
        }
        LimitLatch latch = connectionLimitLatch;
        if (latch!=null) {
            latch.countUpOrAwait();
        }
    }
}

        LimitLatch 

         connectionLimitLatch的实现类为LimitLatch,通过其源码可以发现其定义了三个成员变量sync、count、limit分别用来管理并发锁、记录请求数与最大连接限制。

public abstract class AbstractEndpoint<S,U> { 
   protected LimitLatch initializeConnectionLatch() {
        if (maxConnections==-1) {
            return null;
        }
        if (connectionLimitLatch==null) {
            connectionLimitLatch = new LimitLatch(getMaxConnections());
        }
        return connectionLimitLatch;
    }
}

public class LimitLatch {
    private final Sync sync;
    private final AtomicLong count;
    private volatile long limit;

    public LimitLatch(long limit) {
        this.limit = limit;
        this.count = new AtomicLong(0);
        this.sync = new Sync();
    }
}

        tryAcquireShared 

        回到上文中判断最大连接数的步骤latch.countUpOrAwait,我们进入到LimitLatch 中来看下。这里最终会进入tryAcquireShared方法,将count加1后判断是否已超出限制,然后再做进一步判断与处理。

public class LimitLatch {
    public void countUpOrAwait() throws InterruptedException {
        sync.acquireSharedInterruptibly(1);
    }

    private class Sync extends AbstractQueuedSynchronizer {
        @Override
        protected int tryAcquireShared(int ignored) {
            long newCount = count.incrementAndGet();
            if (!released && newCount > limit) {
                // Limit exceeded
                count.decrementAndGet();
                return -1;
            } else {
                return 1;
            }
        }
}

public abstract class AbstractQueuedSynchronizer extends AbstractOwnableSynchronizer
    implements java.io.Serializable {
    public final void acquireSharedInterruptibly(int arg)
            throws InterruptedException {
        if (Thread.interrupted())
            throw new InterruptedException();
        if (tryAcquireShared(arg) < 0)
            doAcquireSharedInterruptibly(arg);
    }
}

        serverSocketAccept

        这一步也是调用的endpoint中的方法,从下文的源码中可以看出这里是从endpoint执行init方法时创建的ServerSocketChannel中获取SocketChannel 连接。在nio中,可以认为一个 SocketChannel 对象代表一个服务端与客户端的连接。

public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel> {   
    @Override
    protected SocketChannel serverSocketAccept() throws Exception {
        SocketChannel result = serverSock.accept();
        // ...
        return result;
    }
}

        setSocketOptions

        setSocketOptions也是endpoint中的方法,这里会执行以下几步:

        (1)尝试从SynchronizedStack<NioChannel> nioChannels 中获取信道

        (2)如果上一步未获取到则创建SocketBufferHandler对象

        (3)使用SocketBufferHandler对象创建NioChannel对象

        (4)使用NioChannel与NioEndpoint对象创建NioSocketWrapper对象

        (5)为NioChannel对象设置SocketChannel与NioSocketWrapper对象作为属性

        (6)为NioSocketWrapper对象设置属性并注册入poller中

public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel> { 
   @Override
    protected boolean setSocketOptions(SocketChannel socket) {
        NioSocketWrapper socketWrapper = null;
        try {
            // Allocate channel and wrapper
            NioChannel channel = null;
            if (nioChannels != null) {
                channel = nioChannels.pop();
            }
            if (channel == null) {
                SocketBufferHandler bufhandler = new SocketBufferHandler(
                        socketProperties.getAppReadBufSize(),
                        socketProperties.getAppWriteBufSize(),
                        socketProperties.getDirectBuffer());
                if (isSSLEnabled()) {
                    channel = new SecureNioChannel(bufhandler, this);
                } else {
                    channel = new NioChannel(bufhandler);
                }
            }
            NioSocketWrapper newWrapper = new NioSocketWrapper(channel, this);
            channel.reset(socket, newWrapper);
            connections.put(socket, newWrapper);
            socketWrapper = newWrapper;

            // Set socket properties
            // Disable blocking, polling will be used
            socket.configureBlocking(false);
            socketProperties.setProperties(socket.socket());

            socketWrapper.setReadTimeout(getConnectionTimeout());
            socketWrapper.setWriteTimeout(getConnectionTimeout());
            socketWrapper.setKeepAliveLeft(NioEndpoint.this.getMaxKeepAliveRequests());
            poller.register(socketWrapper);
            return true;
        } catch (Throwable t) {
            ExceptionUtils.handleThrowable(t);
            try {
                log.error(sm.getString("endpoint.socketOptionsError"), t);
            } catch (Throwable tt) {
                ExceptionUtils.handleThrowable(tt);
            }
            if (socketWrapper == null) {
                destroySocket(socket);
            }
        }
        // Tell to close the socket if needed
        return false;
    }
}

        SocketBufferHandler

        SocketBufferHandler对象里包含了两个 ByteBuffer 对象,一个读一个写。

    public SocketBufferHandler(int readBufferSize, int writeBufferSize,
            boolean direct) {
        this.direct = direct;
        if (direct) {
            readBuffer = ByteBuffer.allocateDirect(readBufferSize);
            writeBuffer = ByteBuffer.allocateDirect(writeBufferSize);
        } else {
            readBuffer = ByteBuffer.allocate(readBufferSize);
            writeBuffer = ByteBuffer.allocate(writeBufferSize);
        }
    }

        NioChannel

        NioChannel 中将SocketBufferHandler 与SocketChannel 、NioSocketWrapper 作为成员变量,初始化时只设置了一个SocketBufferHandler,而另外两个成员会在rest时设置。

public class NioChannel implements ByteChannel, ScatteringByteChannel, GatheringByteChannel {
    protected final SocketBufferHandler bufHandler;
    protected SocketChannel sc = null;
    protected NioSocketWrapper socketWrapper = null;

    public NioChannel(SocketBufferHandler bufHandler) {
        this.bufHandler = bufHandler;
    }

    // Reset the channel
    public void reset(SocketChannel channel, NioSocketWrapper socketWrapper) throws IOException {
        this.sc = channel;
        this.socketWrapper = socketWrapper;
        bufHandler.reset();
    }
}

        NioSocketWrapper

        NioSocketWrapper是更多组件的封装,可以看到这里从NioEndpoint中获取了nioChannels 与poller,又从niochannel中获取了socketBufferHandler,而其父类中则保存了作为参数传入的SocketChannel 与当前的endpoint对象。

   public static class NioSocketWrapper extends SocketWrapperBase<NioChannel> { 
       public NioSocketWrapper(NioChannel channel, NioEndpoint endpoint) {
            super(channel, endpoint);
            nioChannels = endpoint.getNioChannels();
            poller = endpoint.getPoller();
            socketBufferHandler = channel.getBufHandler();
            readLock = (readPending == null) ? new Object() : readPending;
            writeLock = (writePending == null) ? new Object() : writePending;
        }
    }

    public abstract class SocketWrapperBase<E> {
      public SocketWrapperBase(E socket, AbstractEndpoint<E,?> endpoint) {
            this.socket = socket;
            this.endpoint = endpoint;
            if (endpoint.getUseAsyncIO() || needSemaphores()) {
                readPending = new Semaphore(1);
                writePending = new Semaphore(1);
            } else {
                readPending = null;
                writePending = null;
            }
        }
    }

         方法的最后将封装好的NioSocketWrapper对象注册到了poller对象中,由此将连接请求转发了过去。

        大致梳理下Acceptor的作用就是使线程在一个循环里一直接受客户端连接,生成 SocketChannel 对象,并把这个 SocketChannel 对象封装成 NioChannel 和 NioSocketWrapper 对象,并注册到 Poller 对象中等待进一步处理。

二、Poller与PollerEvent

        1、PollerEvent

        PollerEvent是向Poller对象的事件队列插入的待处理的事件的抽象,可以被Poller缓存循环回收利用以避免GC。

        可以看到构造方法内部实际是调用了rest方法将设置传入的两个参数,即我们上一节中介绍的NioSocketWrapper 与intOps(请求关注的事件类型,是连接、读还是写)。

    /**
     * PollerEvent, cacheable object for poller events to avoid GC
     */
    public static class PollerEvent {

        private NioSocketWrapper socketWrapper;
        private int interestOps;

        public PollerEvent(NioSocketWrapper socketWrapper, int intOps) {
            reset(socketWrapper, intOps);
        }

        public void reset(NioSocketWrapper socketWrapper, int intOps) {
            this.socketWrapper = socketWrapper;
            interestOps = intOps;
        }

        public NioSocketWrapper getSocketWrapper() {
            return socketWrapper;
        }

        public int getInterestOps() {
            return interestOps;
        }

        public void reset() {
            reset(null, 0);
        }
}

        2、poller

        Poller类在构造方法中会获取一个选择器,这是NIO中的关键组件,用于获取就绪事件。

    public class Poller implements Runnable {
        private Selector selector;
        public Poller() throws IOException {
            this.selector = Selector.open();
    }
        

       register

        先来看下上文中涉及的register方法,这个方法是将新连接的套接字创建为PollerEvent对象并缓存起来。这里的第一步是向NioSocketWrapper 中注册关注事件,这里默认是读事件,然后调用createPollerEvent方法创建PollerEvent对象最后调用addEvent对象进行缓存。

        /**
         * Registers a newly created socket with the poller.
         *
         * @param socketWrapper The socket wrapper
         */
        public void register(final NioSocketWrapper socketWrapper) {
            socketWrapper.interestOps(SelectionKey.OP_READ);//this is what OP_REGISTER turns into.
            PollerEvent pollerEvent = createPollerEvent(socketWrapper, OP_REGISTER);
            addEvent(pollerEvent);
        }

        createPollerEvent、addEvent

        createPollerEvent方法尝试从缓存中获取现有的PollerEvent,如果没有则新建一个,有的话则调用rest方法重置其套接字等设置。

        addEvent则是将上一步获取到的PollerEvent加入到events事件缓存中,等待分配线程处理。

public class Poller implements Runnable { 
       private final SynchronizedQueue<PollerEvent> events =
                new SynchronizedQueue<>();

        private PollerEvent createPollerEvent(NioSocketWrapper socketWrapper, int interestOps) {
            PollerEvent r = null;
            if (eventCache != null) {
                r = eventCache.pop();
            }
            if (r == null) {
                r = new PollerEvent(socketWrapper, interestOps);
            } else {
                r.reset(socketWrapper, interestOps);
            }
            return r;
        }

        private void addEvent(PollerEvent event) {
            events.offer(event);
            if (wakeupCounter.incrementAndGet() == 0) {
                selector.wakeup();
            }
        }
}

       run

        然后来看poller的run方法,首先调用了events()方法,获取就绪事件数量keyCount ,遍历这些就绪事件并调用processKey方法处理,传入的参数为连接的SelectionKey与NioSocketWrapper。

        PS:selectionKey表示channel在Selector中注册的标识,每个Channel向Selector注册时,都将会创建一个selectionKey

    public class Poller implements Runnable {
        public void run() {
            // Loop until destroy() is called
            while (true) {
                boolean hasEvents = false;
                try {
                    if (!close) {
                        hasEvents = events();
                        if (wakeupCounter.getAndSet(-1) > 0) {
                            // If we are here, means we have other stuff to do
                            // Do a non blocking select
                            keyCount = selector.selectNow();
                        } else {
                            keyCount = selector.select(selectorTimeout);
                        }
                        wakeupCounter.set(0);
                    }
                    if (close) {
                        // ...
                    }
                    // Either we timed out or we woke up, process events first
                    if (keyCount == 0) {
                        hasEvents = (hasEvents | events());
                    }
                } catch (Throwable x) {
                    ExceptionUtils.handleThrowable(x);
                    log.error(sm.getString("endpoint.nio.selectorLoopError"), x);
                    continue;
                }

                Iterator<SelectionKey> iterator =
                    keyCount > 0 ? selector.selectedKeys().iterator() : null;
                // Walk through the collection of ready keys and dispatch
                // any active event.
                while (iterator != null && iterator.hasNext()) {
                    SelectionKey sk = iterator.next();
                    iterator.remove();
                    NioSocketWrapper socketWrapper = (NioSocketWrapper) sk.attachment();
                    // Attachment may be null if another thread has called
                    // cancelledKey()
                    if (socketWrapper != null) {
                        processKey(sk, socketWrapper);
                    }
                }
                // Process timeouts
                timeout(keyCount,hasEvents);
            }
            getStopLatch().countDown();
        }
    }

       events

        来看events方法,内部会遍历PollerEvent 缓存集合events,获取其中的NioSocketWrapper 、SocketChannel 以及关注的事件interestOps 。如果是注册事件则将当前通道的OP_READ事件注册到selector上,同时添加附件NioSocketWrapper 对象,如果是别的事件则将其附加到 SocketChannel 关联的 SelectionKey 。

        public boolean events() {
            boolean result = false;

            PollerEvent pe = null;
            for (int i = 0, size = events.size(); i < size && (pe = events.poll()) != null; i++ ) {
                result = true;
                NioSocketWrapper socketWrapper = pe.getSocketWrapper();
                SocketChannel sc = socketWrapper.getSocket().getIOChannel();
                int interestOps = pe.getInterestOps();
                if (sc == null) {
                    log.warn(sm.getString("endpoint.nio.nullSocketChannel"));
                    socketWrapper.close();
                } else if (interestOps == OP_REGISTER) {
                    try {
                        sc.register(getSelector(), SelectionKey.OP_READ, socketWrapper);
                    } catch (Exception x) {
                        log.error(sm.getString("endpoint.nio.registerFail"), x);
                    }
                } else {
                    final SelectionKey key = sc.keyFor(getSelector());
                    if (key == null) {
                        socketWrapper.close();
                    } else {
                        final NioSocketWrapper attachment = (NioSocketWrapper) key.attachment();
                        if (attachment != null) {
                            try {
                                int ops = key.interestOps() | interestOps;
                                attachment.interestOps(ops);
                                key.interestOps(ops);
                            } catch (CancelledKeyException ckx) {
                                cancelledKey(key, socketWrapper);
                            }
                        } else {
                            cancelledKey(key, socketWrapper);
                        }
                    }
                }
                if (running && eventCache != null) {
                    pe.reset();
                    eventCache.push(pe);
                }
            }

            return result;
        }

     processKey

        run方法中调用processKey方法来处理请求,首先是判断socketWrapper.getSendfileData() 不为 null 的话就调用 processSendfile 方法处理。

        然后判断是读还是写事件,NioSocketWrapper 是在上文中的setSocketOptions方法创建的,这里的readOperation、writeOperation  为空,readBlocking、writeBlocking为false,因此最终实际上会调用processSocket方法,该方法由AbstractEndpoint类实现,我们会在以后介绍。

        protected void processKey(SelectionKey sk, NioSocketWrapper socketWrapper) {
            try {
                if (close) {
                    cancelledKey(sk, socketWrapper);
                } else if (sk.isValid()) {
                    if (sk.isReadable() || sk.isWritable()) {
                        if (socketWrapper.getSendfileData() != null) {
                            processSendfile(sk, socketWrapper, false);
                        } else {
                            unreg(sk, socketWrapper, sk.readyOps());
                            boolean closeSocket = false;
                            // Read goes before write
                            if (sk.isReadable()) {
                                if (socketWrapper.readOperation != null) {
                                    if (!socketWrapper.readOperation.process()) {
                                        closeSocket = true;
                                    }
                                } else if (socketWrapper.readBlocking) {
                                    synchronized (socketWrapper.readLock
                                    ) {
                                        socketWrapper.readBlocking = false;
                                        socketWrapper.readLock.notify();
                                    }
                                } else if (!processSocket(socketWrapper, SocketEvent.OPEN_READ, true)) {
                                    closeSocket = true;
                                }
                            }
                            if (!closeSocket && sk.isWritable()) {
                                if (socketWrapper.writeOperation != null) {
                                    if (!socketWrapper.writeOperation.process()) {
                                        closeSocket = true;
                                    }
                                } else if (socketWrapper.writeBlocking) {
                                    synchronized (socketWrapper.writeLock) {
                                        socketWrapper.writeBlocking = false;
                                        socketWrapper.writeLock.notify();
                                    }
                                } else if (!processSocket(socketWrapper, SocketEvent.OPEN_WRITE, true)) {
                                    closeSocket = true;
                                }
                            }
                            if (closeSocket) {
                                cancelledKey(sk, socketWrapper);
                            }
                        }
                    }
                } else {
                    // Invalid key
                    cancelledKey(sk, socketWrapper);
                }
            } catch (CancelledKeyException ckx) {
                cancelledKey(sk, socketWrapper);
            } catch (Throwable t) {
                ExceptionUtils.handleThrowable(t);
                log.error(sm.getString("endpoint.nio.keyProcessingError"), t);
            }
        }

        到这里我们基本介绍完了请求是如何从Acceptor流转到Poller中的,异步线程Acceptor在接收到请求后会创建了SocketChannel 对象,接着先封装为NioSocketWrapper,再封装为PollerEvent,然后转交给Poller线程处理。Poller线程在拿到PollerEvent后会取出其中的SocketChannel对象并注册相关事件,最后调用processKey来进行下一步处理。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/569267.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

绝对不能错过的7个零基础免费的ChatGPT镜像网站

还在为打不开openai官网烦心&#xff1f;本文帮你实现ChatGPTMidJourney自由(&#xffe3;∇&#xffe3;)/ &#x1f4d2;收集了一些截至目前(2023年5月25日午12:00)可以免费访问&#xff0c;并且零基础也能正常使用的镜像网站&#xff0c;后续将持续维护更新(&#xff61;&a…

(2)lordPE脱壳

1.寻找OEP 1.1第一种情况 1.修改OD选项&#xff0c;调试设置"事件"为系统断点&#xff0c;直接打开"查看"->"内存",设置00400000下F2断点&#xff0c;单步F8找到0040****开头的OEP例如&#xff1a;00401528 1.2第二种情况 进入od后如果直…

Github疯传!200本经典计算机书籍!

好书在精不在多&#xff0c;每一本经典书籍都值得反复翻阅&#xff0c;温故而知新&#xff01; 下面分享几本计算机经典书籍&#xff0c;都是我自己看过的。 重构 改善既有代码的设计 就像豆瓣评论所说的&#xff0c;看后有种醍醐灌顶、欲罢不能的感觉。无论你是初学者&#…

数据结构与算法02:数组和链表

目录 【数组】 为什么Go语言的切片是成倍扩容&#xff1f; 【链表】 单链表 循环链表 双向链表 双向循环链表 数组和链表如何选择&#xff1f; 如何使用链表实现 LRU 缓存淘汰算法&#xff1f; 链表的一些操作 【每日一练】 【数组】 数组&#xff08;Array&#…

JMeter参数化四种实现方式

1 参数化释义 什么是参数化&#xff1f;从字面上去理解的话&#xff0c;就是事先准备好数据&#xff08;广义上来说&#xff0c;可以是具体的数据值&#xff0c;也可以是数据生成规则&#xff09;&#xff0c;而非在脚本中写死&#xff0c;脚本执行时从准备好的数据中取值。 参…

Sentinel热点key

1.基本介绍 官方文档 何为热点&#xff1f;热点即经常访问的数据。很多时候我们希望统计某个热点数据中访问频次最高的 Top K 数据&#xff0c;并对其访问进行限制。比如&#xff1a; 商品 ID 为参数&#xff0c;统计一段时间内最常购买的商品 ID 并进行限制用户 ID 为参数&…

HyDE、UDAPDR(LLM大模型用于信息检索)

本篇博文继续整理LLM在搜索推荐领域的应用&#xff0c;往期文章请往博主主页查看更多。 Precise Zero-Shot Dense Retrieval without Relevance Labels 这篇文章主要做zero-shot场景下的稠密检索&#xff0c;通过借助LLM的力量不需要Relevance Labels&#xff0c;开箱即用。作…

【数据结构】---几分钟简单几步学会手撕链式二叉树(上)

文章目录 前言&#x1f31f;一、二叉树链式结构的实现&#x1f30f;1.1 前置说明&#x1f4ab;快速创建一棵简单的二叉树 &#x1f30f;1.2 二叉树的遍历的时间、空间复杂度&#x1f30f;1.3 二叉树的遍历&#x1f4ab;1.3.1 前序、中序以及后序遍历&#xff1a;&#x1f4ab;1…

深入理解hashmap底层实现原理

目录 总体介绍 HashMap元素的存储 在hashmap中添加元素 HashMap的扩容机制 HashMap的线程安全性 1.添加和删除元素时存在不安全性 2.进行扩容操作时存在不安全性 3.哈希冲突存在不安全性 4.线程之间的不可见性导致安全问题 总体介绍 HashMap是我们用于元素映射使用频率最…

MySQL——子查询

来一篇 MySQL-子查询 记录一下这个美好的时光,学习记录篇,下文中所有SQL 语句 均可在 MySQL DB 学习Demo 此处下载SQL语句执行,有相关DB 与 表。 1. 需求分析与问题解决 1.1 实际问题 现有解决方式一: SELECT salary FROM employees WHERE last_name = Abel SELECT last…

【算法】【算法杂谈】旋转数组的二分法查找

aTOC 前言 当前所有算法都使用测试用例运行过&#xff0c;但是不保证100%的测试用例&#xff0c;如果存在问题务必联系批评指正~ 在此感谢左大神让我对算法有了新的感悟认识&#xff01; 问题介绍 原问题 给定一个从小到大有序的数组&#xff0c;该数组存在重复的数&#xf…

【数据安全-02】AI打假利器数字水印,及java+opencv实现

AIGC 的火爆引燃了数字水印&#xff0c;说实话数字水印并不是一项新的技术&#xff0c;但是这时候某些公司拿出来宣传一下特别应景&#xff0c;相应股票蹭蹭地涨。数字水印是什么呢&#xff0c;顾名思义&#xff0c;和我们在pdf中打的水印作用差不多&#xff0c;起到明确版权、…

【拒绝爆零】C++编程考试常见栽区

前言 在OI赛制中&#xff0c;我们可能会因为一些细节原因导致题目爆零。下面&#xff0c;是我列举的一些常见的坑&#xff1a; 1.极值未赋值 这个错误在运行时就能检查出来&#xff0c;但还是会浪费一定的时间&#xff0c;所以我们还是避开这些小插曲为好。 2.定义变量遇到…

利用无代码工具开发一款小程序

目录 无代码工具开发小程序的流程需求分析阶段模型设计阶段页面搭建阶段创建项目创建数据表组件搭建 预览发布总结 日常我们开发小程序的时候都是要从写代码开始&#xff0c;但是写代码这个事只有专业开发才可以干&#xff0c;那作为普通人&#xff0c;如果也希望开发小程序&am…

前端小工具:批量修改图片信息

前端小工具一&#xff1a;批量修改文件夹里面的图片名称 步骤&#xff1a; 1.安装nodejs。 2.根据需要修改editFileName(filePath, formatName)函数的参数&#xff0c;也可以不改&#xff0c;直接将renameFile.js和img文件夹放在同一个目录下。 3.在renameFile.js目录下开启…

Linux:ext文件系统配额

1. 创建三个用户test1 test2 test3 2. 创建一个组 test_23 3. 把 test2 和 test3 加入test_23组 首先要有quota这个软件 如果没有用yum安装 yum -y install quota 如果不会搭建yum Linux&#xff1a;rpm查询安装 && yum安装_鲍海超-GNUBHCkalitarro的博客…

计算机组成原理-存储系统-缓存存储器(Cache)

目录 一、Cache基本概念 1.2性能分析 二、 Cache和主存的映射发生 ​​​​​​2.1全相连映射​编辑 2.2直接映射​编辑 2.3组相连映射 三、Cachae的替换算法 3.1 随机算法(RADN) 3.2 先进先出算法(FIFO) 3.3 近期最少使用(LRU) 3.4 最近不经常使用(LFU) 四、写策略 4…

kali安装ARL灯塔过程

&#xff08;一&#xff09;安装docker环境 1、检查是否存在docker环境 docker 2、如果没有docker&#xff0c;就先安装docker apt install docker.io 出现 unable to locate package docker.io这些&#xff0c;这是因为没有跟新 输入跟新命令&#xff1a; apt-get update 在…

把ChatGPT的所有插件整理成中文后!真要说卧槽了..

大家好&#xff0c;我是五竹。 ChatGPT如约向用户开放了联网功能和众多插件&#xff0c;五竹从上周开始满怀着热情等待着&#xff0c;看别人的测评效果都快把我羡慕哭了。最终等来的却是Plus账号给封了&#xff0c;而且至今也没有续上&#xff0c;只能说非常无奈。算了&#x…

探究低代码平台解决企业痛点的能力

近年来&#xff0c;随着越来越多的公司寻找改善数字化转型过程的方法&#xff0c;低代码平台的受欢迎程度一直在上升。低代码平台允许以最小的编码要求创建软件应用程序&#xff0c;从而减少与传统软件开发相关的时间和成本。今天&#xff0c;小编将聊一聊低代码平台能解决哪些…