Android之Handler分析与理解

news2024/9/23 3:24:14

Android中的Handler是一个用于处理消息和线程间通信的机制。它可以将Runnable对象或Message对象发送到特定的线程中进行处理。
使用Handler的主要目的是在不同的线程之间进行通信,特别是在后台线程中执行一些任务后,将结果发送到UI线程进行更新。
流程图:
在这里插入图片描述
下面是一个示例代码,演示如何创建Message对象并发送给Handler:

 // 创建一个Handler对象
Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        // 在UI线程中处理接收到的消息
        switch (msg.what) {
            case 1:
                // 处理消息类型为1的情况
                String messageText = (String) msg.obj;
                // 执行相应的操作
                break;
            case 2:
                // 处理消息类型为2的情况
                // 执行相应的操作
                break;
            // 可以根据需要处理其他消息类型
        }
    }
};

// 在其他线程中创建并发送Message对象
Thread thread = new Thread(new Runnable() {
    @Override
    public void run() {
        // 创建一个Message对象
        Message message = handler.obtainMessage();
        
        // 设置消息类型
        message.what = 1;
        
        // 设置消息内容
        message.obj = "Hello, Handler!";
        
        // 发送消息给Handler所关联的线程
        handler.sendMessage(message);
    }
});

// 启动线程
thread.start();

Handler源码分析

第一条主线:入队(谁入的队?怎么入的?入的什么队?)

首先进入handler.sendMessage(msg);

    /**
     * Pushes a message onto the end of the message queue after all pending messages
     * before the current time. It will be received in {@link #handleMessage},
     * in the thread attached to this handler.
     *  
     * @return Returns true if the message was successfully placed in to the 
     *         message queue.  Returns false on failure, usually because the
     *         looper processing the message queue is exiting.
     */
    public final boolean sendMessage(@NonNull Message msg) {
        return sendMessageDelayed(msg, 0);
    }

再点进来sendMessageDelayed(msg, 0);

    /**
     * Enqueue a message into the message queue after all pending messages
     * before (current time + delayMillis). You will receive it in
     * {@link #handleMessage}, in the thread attached to this handler.
     *  
     * @return Returns true if the message was successfully placed in to the 
     *         message queue.  Returns false on failure, usually because the
     *         looper processing the message queue is exiting.  Note that a
     *         result of true does not mean the message will be processed -- if
     *         the looper is quit before the delivery time of the message
     *         occurs then the message will be dropped.
     */
    public final boolean sendMessageDelayed(@NonNull Message msg, long delayMillis) {
        if (delayMillis < 0) {
            delayMillis = 0;
        }
        return sendMessageAtTime(msg, SystemClock.uptimeMillis() + delayMillis);
    }

再进来sendMessageAtTime(msg, SystemClock.uptimeMillis() + delayMillis)

    public boolean sendMessageAtTime(@NonNull Message msg, long uptimeMillis) {
        MessageQueue queue = mQueue;
        if (queue == null) {
            RuntimeException e = new RuntimeException(
                    this + " sendMessageAtTime() called with no mQueue");
            Log.w("Looper", e.getMessage(), e);
            return false;
        }
        return enqueueMessage(queue, msg, uptimeMillis);
    }

进入enqueueMessage(queue, msg, uptimeMillis)

    private boolean enqueueMessage(@NonNull MessageQueue queue, @NonNull Message msg,
            long uptimeMillis) {
        msg.target = this;
        msg.workSourceUid = ThreadLocalWorkSource.getUid();

        if (mAsynchronous) {
            msg.setAsynchronous(true);
        }
        return queue.enqueueMessage(msg, uptimeMillis);
    }

queue.enqueueMessage(msg, uptimeMillis)其实执行的是Message的enqueueMessage方法

 boolean enqueueMessage(Message msg, long when) {
        if (msg.target == null) {
            throw new IllegalArgumentException("Message must have a target.");
        }

        synchronized (this) {
            if (msg.isInUse()) {
                throw new IllegalStateException(msg + " This message is already in use.");
            }

            if (mQuitting) {
                IllegalStateException e = new IllegalStateException(
                        msg.target + " sending message to a Handler on a dead thread");
                Log.w(TAG, e.getMessage(), e);
                msg.recycle();
                return false;
            }
            //对msg进入标记
            msg.markInUse();
            msg.when = when;
            Message p = mMessages;
            boolean needWake;
            //如果队列中没有数据,将消息放入头部
            if (p == null || when == 0 || when < p.when) {
                // New head, wake up the event queue if blocked.
                msg.next = p;
                mMessages = msg;
                needWake = mBlocked;
            } else {
                // Inserted within the middle of the queue.  Usually we don't have to wake
                // up the event queue unless there is a barrier at the head of the queue
                // and the message is the earliest asynchronous message in the queue.
                needWake = mBlocked && p.target == null && msg.isAsynchronous();
                Message prev;
                for (;;) {
                    prev = p;
                    p = p.next;
                    if (p == null || when < p.when) {
                        break;
                    }
                    if (needWake && p.isAsynchronous()) {
                        needWake = false;
                    }
                }
                msg.next = p; // invariant: p == prev.next
                prev.next = msg;
            }

            // We can assume mPtr != 0 because mQuitting is false.
            if (needWake) {
                nativeWake(mPtr);
            }
        }
        return true;
    }

说明了入队的过程是:Handler.sendMessage()->sendMessageDelayed()->sendMessageAtTime()->enqueueMessage()->MessageQueue类的enqueueMessage()
Handler发送消息(message)进行入队(MessageQueue)
入队时,如果队列中没有数据,直接将msg放到头部;如果有,则需要遍历队列中的数据,进入插入操作;

第二条主线出队(消费)

app启动的时候会调用ActivityThread这个类
会调用ActivityThread类中的main方法

 public static void main(String[] args) {
        Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "ActivityThreadMain");

        // Install selective syscall interception
        AndroidOs.install();

        // CloseGuard defaults to true and can be quite spammy.  We
        // disable it here, but selectively enable it later (via
        // StrictMode) on debug builds, but using DropBox, not logs.
        CloseGuard.setEnabled(false);

        Environment.initForCurrentUser();

        // Make sure TrustedCertificateStore looks in the right place for CA certificates
        final File configDir = Environment.getUserConfigDirectory(UserHandle.myUserId());
        TrustedCertificateStore.setDefaultUserDirectory(configDir);

        // Call per-process mainline module initialization.
        initializeMainlineModules();

        Process.setArgV0("<pre-initialized>");

        Looper.prepareMainLooper();

        // Find the value for {@link #PROC_START_SEQ_IDENT} if provided on the command line.
        // It will be in the format "seq=114"
        long startSeq = 0;
        if (args != null) {
            for (int i = args.length - 1; i >= 0; --i) {
                if (args[i] != null && args[i].startsWith(PROC_START_SEQ_IDENT)) {
                    startSeq = Long.parseLong(
                            args[i].substring(PROC_START_SEQ_IDENT.length()));
                }
            }
        }
        ActivityThread thread = new ActivityThread();
        thread.attach(false, startSeq);

        if (sMainThreadHandler == null) {
            sMainThreadHandler = thread.getHandler();
        }

        if (false) {
            Looper.myLooper().setMessageLogging(new
                    LogPrinter(Log.DEBUG, "ActivityThread"));
        }

        // End of event ActivityThreadMain.
        Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
        Looper.loop();

        throw new RuntimeException("Main thread loop unexpectedly exited");
    }

点进去看Looper.loop();

  /**
     * Run the message queue in this thread. Be sure to call
     * {@link #quit()} to end the loop.
     */
    public static void loop() {
        final Looper me = myLooper();
        if (me == null) {
            throw new RuntimeException("No Looper; Looper.prepare() wasn't called on this thread.");
        }
        if (me.mInLoop) {
            Slog.w(TAG, "Loop again would have the queued messages be executed"
                    + " before this one completed.");
        }

        me.mInLoop = true;
        final MessageQueue queue = me.mQueue;

        // Make sure the identity of this thread is that of the local process,
        // and keep track of what that identity token actually is.
        Binder.clearCallingIdentity();
        final long ident = Binder.clearCallingIdentity();

        // Allow overriding a threshold with a system prop. e.g.
        // adb shell 'setprop log.looper.1000.main.slow 1 && stop && start'
        final int thresholdOverride =
                SystemProperties.getInt("log.looper."
                        + Process.myUid() + "."
                        + Thread.currentThread().getName()
                        + ".slow", 0);

        boolean slowDeliveryDetected = false;

        for (;;) {
            Message msg = queue.next(); // might block
            if (msg == null) {
                // No message indicates that the message queue is quitting.
                return;
            }

            // This must be in a local variable, in case a UI event sets the logger
            final Printer logging = me.mLogging;
            if (logging != null) {
                logging.println(">>>>> Dispatching to " + msg.target + " " +
                        msg.callback + ": " + msg.what);
            }
            // Make sure the observer won't change while processing a transaction.
            final Observer observer = sObserver;

            final long traceTag = me.mTraceTag;
            long slowDispatchThresholdMs = me.mSlowDispatchThresholdMs;
            long slowDeliveryThresholdMs = me.mSlowDeliveryThresholdMs;
            if (thresholdOverride > 0) {
                slowDispatchThresholdMs = thresholdOverride;
                slowDeliveryThresholdMs = thresholdOverride;
            }
            final boolean logSlowDelivery = (slowDeliveryThresholdMs > 0) && (msg.when > 0);
            final boolean logSlowDispatch = (slowDispatchThresholdMs > 0);

            final boolean needStartTime = logSlowDelivery || logSlowDispatch;
            final boolean needEndTime = logSlowDispatch;

            if (traceTag != 0 && Trace.isTagEnabled(traceTag)) {
                Trace.traceBegin(traceTag, msg.target.getTraceName(msg));
            }

            final long dispatchStart = needStartTime ? SystemClock.uptimeMillis() : 0;
            final long dispatchEnd;
            Object token = null;
            if (observer != null) {
                token = observer.messageDispatchStarting();
            }
            long origWorkSource = ThreadLocalWorkSource.setUid(msg.workSourceUid);
            try {
                msg.target.dispatchMessage(msg);
                if (observer != null) {
                    observer.messageDispatched(token, msg);
                }
                dispatchEnd = needEndTime ? SystemClock.uptimeMillis() : 0;
            } catch (Exception exception) {
                if (observer != null) {
                    observer.dispatchingThrewException(token, msg, exception);
                }
                throw exception;
            } finally {
                ThreadLocalWorkSource.restore(origWorkSource);
                if (traceTag != 0) {
                    Trace.traceEnd(traceTag);
                }
            }
            if (logSlowDelivery) {
                if (slowDeliveryDetected) {
                    if ((dispatchStart - msg.when) <= 10) {
                        Slog.w(TAG, "Drained");
                        slowDeliveryDetected = false;
                    }
                } else {
                    if (showSlowLog(slowDeliveryThresholdMs, msg.when, dispatchStart, "delivery",
                            msg)) {
                        // Once we write a slow delivery log, suppress until the queue drains.
                        slowDeliveryDetected = true;
                    }
                }
            }
            if (logSlowDispatch) {
                showSlowLog(slowDispatchThresholdMs, dispatchStart, dispatchEnd, "dispatch", msg);
            }

            if (logging != null) {
                logging.println("<<<<< Finished to " + msg.target + " " + msg.callback);
            }

            // Make sure that during the course of dispatching the
            // identity of the thread wasn't corrupted.
            final long newIdent = Binder.clearCallingIdentity();
            if (ident != newIdent) {
                Log.wtf(TAG, "Thread identity changed from 0x"
                        + Long.toHexString(ident) + " to 0x"
                        + Long.toHexString(newIdent) + " while dispatching to "
                        + msg.target.getClass().getName() + " "
                        + msg.callback + " what=" + msg.what);
            }

            msg.recycleUnchecked();
        }
    }

在for循环中有Message msg = queue.next();在MessageQueue的next()可以发现

 @UnsupportedAppUsage
    Message next() {
        // Return here if the message loop has already quit and been disposed.
        // This can happen if the application tries to restart a looper after quit
        // which is not supported.
        final long ptr = mPtr;
        if (ptr == 0) {
            return null;
        }

        int pendingIdleHandlerCount = -1; // -1 only during first iteration
        int nextPollTimeoutMillis = 0;
        for (;;) {
            if (nextPollTimeoutMillis != 0) {
                Binder.flushPendingCommands();
            }

            nativePollOnce(ptr, nextPollTimeoutMillis);

            synchronized (this) {
                // Try to retrieve the next message.  Return if found.
                final long now = SystemClock.uptimeMillis();
                Message prevMsg = null;
                Message msg = mMessages;
                if (msg != null && msg.target == null) {
                    // Stalled by a barrier.  Find the next asynchronous message in the queue.
                    do {
                        prevMsg = msg;
                        msg = msg.next;
                    } while (msg != null && !msg.isAsynchronous());
                }
                if (msg != null) {
                    if (now < msg.when) {
                        // Next message is not ready.  Set a timeout to wake up when it is ready.
                        nextPollTimeoutMillis = (int) Math.min(msg.when - now, Integer.MAX_VALUE);
                    } else {
                        // Got a message.
                        mBlocked = false;
                        if (prevMsg != null) {
                            prevMsg.next = msg.next;
                        } else {
                            mMessages = msg.next;
                        }
                        msg.next = null;
                        if (DEBUG) Log.v(TAG, "Returning message: " + msg);
                        msg.markInUse();
                        return msg;
                    }
                } else {
                    // No more messages.
                    nextPollTimeoutMillis = -1;
                }

                // Process the quit message now that all pending messages have been handled.
                if (mQuitting) {
                    dispose();
                    return null;
                }

                // If first time idle, then get the number of idlers to run.
                // Idle handles only run if the queue is empty or if the first message
                // in the queue (possibly a barrier) is due to be handled in the future.
                if (pendingIdleHandlerCount < 0
                        && (mMessages == null || now < mMessages.when)) {
                    pendingIdleHandlerCount = mIdleHandlers.size();
                }
                if (pendingIdleHandlerCount <= 0) {
                    // No idle handlers to run.  Loop and wait some more.
                    mBlocked = true;
                    continue;
                }

                if (mPendingIdleHandlers == null) {
                    mPendingIdleHandlers = new IdleHandler[Math.max(pendingIdleHandlerCount, 4)];
                }
                mPendingIdleHandlers = mIdleHandlers.toArray(mPendingIdleHandlers);
            }

            // Run the idle handlers.
            // We only ever reach this code block during the first iteration.
            for (int i = 0; i < pendingIdleHandlerCount; i++) {
                final IdleHandler idler = mPendingIdleHandlers[i];
                mPendingIdleHandlers[i] = null; // release the reference to the handler

                boolean keep = false;
                try {
                    keep = idler.queueIdle();
                } catch (Throwable t) {
                    Log.wtf(TAG, "IdleHandler threw exception", t);
                }

                if (!keep) {
                    synchronized (this) {
                        mIdleHandlers.remove(idler);
                    }
                }
            }

            // Reset the idle handler count to 0 so we do not run them again.
            pendingIdleHandlerCount = 0;

            // While calling an idle handler, a new message could have been delivered
            // so go back and look again for a pending message without waiting.
            nextPollTimeoutMillis = 0;
        }
    }

MessageQueue中for循环取对象,将对象找到返回,此时Looper方法里的msg 就是返回的对象。
并利用msg去调用loop()方法中的dispatchMessage方法

  msg.target.dispatchMessage(msg);

说明了第二条主线的流程是:ActivityThread类的main()->looper.loop()->queue.next()
通过next()找到msg对象,然后通过msg绑定target,也就是handler,调用dispatchMessage回调handleMessage方法

    /**
     * Handle system messages here.
     */
    public void dispatchMessage(@NonNull Message msg) {
        if (msg.callback != null) {
            handleCallback(msg);
        } else {
            if (mCallback != null) {
                if (mCallback.handleMessage(msg)) {
                    return;
                }
            }
            handleMessage(msg);
        }
    }

第三条主线:Handler,MessageQueue,Message,Looper四个类是什么关系,怎么串联?

  1. 在mHandler.obtainMessage()中Handler创建Message对象
  2. 在MessageQueue中的enqueueMessage方法中Handler将创建的对象放入MessageQueue中
  3. Looper是通过ActivityThread的main()方法进行创建,MessageQueue在创建Looper的时会同时创建

ActivityThread类中

Looper.prepareMainLooper();

prepareMainLooper()点进来

    @Deprecated
    public static void prepareMainLooper() {
        prepare(false);
        synchronized (Looper.class) {
            if (sMainLooper != null) {
                throw new IllegalStateException("The main Looper has already been prepared.");
            }
            sMainLooper = myLooper();
        }
    }

进来 prepare(false);

    private static void prepare(boolean quitAllowed) {
        if (sThreadLocal.get() != null) {
            throw new RuntimeException("Only one Looper may be created per thread");
        }
        sThreadLocal.set(new Looper(quitAllowed));
    }

sThreadLocal.set方法中创建了Looper对象

    private Looper(boolean quitAllowed) {
        mQueue = new MessageQueue(quitAllowed);
        mThread = Thread.currentThread();
    }

在创建Looper对象的同时,构造方法里也创建了MessageQueue对象

  1. 在Handler的enqueueMessage方法中,通过msg.target=this将Handler赋值给msg.target对象
    在这里插入图片描述

而我们在调用mHandler.obtainMessage()中

    Message msg= mHandler.obtainMessage();

点进去obtainMessage

    /**
     * Returns a new {@link android.os.Message Message} from the global message pool. More efficient than
     * creating and allocating new instances. The retrieved message has its handler set to this instance (Message.target == this).
     *  If you don't want that facility, just call Message.obtain() instead.
     */
    @NonNull
    public final Message obtainMessage()
    {
        return Message.obtain(this);
    }

进来 Message.obtain(this)

    /**
     * Same as {@link #obtain()}, but sets the value for the <em>target</em> member on the Message returned.
     * @param h  Handler to assign to the returned Message object's <em>target</em> member.
     * @return A Message object from the global pool.
     */
    public static Message obtain(Handler h) {
        Message m = obtain();
        m.target = h;

        return m;
    }

进行obtain()方法

    /**
     * Return a new Message instance from the global pool. Allows us to
     * avoid allocating new objects in many cases.
     */
    public static Message obtain() {
        synchronized (sPoolSync) {
            if (sPool != null) {
                Message m = sPool;
                sPool = m.next;
                m.next = null;
                m.flags = 0; // clear in-use flag
                sPoolSize--;
                return m;
            }
        }
        return new Message();
    }

可以看到在Message.obtain()中message对象采用了复用池,避免资源的浪费;
常见问题解答?如果有错误欢迎指正!
1. 为什么Message需要使用复用机制?每次直接new一个不好么?
当我需要主线程和子线程直接进行沟通的时候一般都使用handler,发送Message对象一般都比较多,如果每发送一次就创建一次的话,会造成资源的浪费,在每次创建Message对象时,都需要分配内存和进行垃圾回收。而使用复用池可以避免频繁地创建和销毁Message对象,从而减少内存的分配和垃圾回收的开销。
Message:单链表结果,链表是非线性,非顺序的物理结构,由N个节点组成;
2. message为什么使用单链表?为啥不使用其他类型:arrayList

  1. arrayList每次创建的时候会创建一个默认大小的空间,如果超过默认大小的空间就需要进行扩容,就需要对这个ArrayList的内存空间重新进行计算和排列,这可能会导致频繁的内存拷贝和垃圾回收。
  2. 由于arrayList需要连续的内存块来存储元素,当我们一个arrayList的内存块不够用的时候,重新去创建一个的话又需要开辟一个内存块,当我们这个内存不够用的时候,我们就会去进行gc操作,而且内存中容易出现内存碎片,如果再存放内存容易奔溃。而单链表只需要分配新的节点,不需要进行大规模的数据迁移,而当我们存放的是一个对象的时候,对内存要求不高,只要有合适的空间都可以存放。

3. 子线程能不能new handler?怎么能在子线程new Handler?
子线程不能直接创建Handler对象,如果需要在子线程new Handler需要调用Looper.prepare()
4 .子线程维护Looper的时候需要注意什么?
注意内存泄露的问题;使用完毕后 记得调用quitSafely的方法
5 .MessageQueue是怎么保证线程安全的
通过synchronized同步关键字来对入队操作进行限定
6 .removeMessage的时候是移除队列中的还是队列外的
remove的时候只能移除队列中的数据
7 .Looper能够prepare两次,为什么?
不能prepare两次,因为Looper在创建过程中就加了约束,如果prepare两次会报错。
在这里插入图片描述

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

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

相关文章

pearsonr 报错:numpy.float64 can not be interpreted as an integer

【1】 模型求出pred&#xff0c;pearsonr(pred,true&#xff09; 出现以下报错&#xff1a; 【2】解释&#xff1a; 当在计算皮尔逊相关系数&#xff08;Pearson correlation coefficient&#xff09;时出现"numpy.float64 can not be interpreted as an integer"的…

7.7~7.8学习总结

StringBuider&#xff1a;线程不安全&#xff0c;效率高 StringBuffer&#xff1a;线程安全&#xff0c;效率低&#xff1b; 用法举例&#xff1a; class TWC {public static void main(String []args){StringBuilder sbnew StringBuilder("小麻子爱吃粑粑");Syst…

C语言学习(三十六)---文件操作

上节内容中&#xff0c;我们学习了练习了动态内存的练习题&#xff0c;并且学习了柔性数组的相关内容&#xff0c;大叫要好好掌握&#xff0c;今天&#xff0c;我们将学习文件操作的相关内容&#xff0c;这部分内容实际上很多&#xff0c;我们以点代面&#xff0c;好了&#xf…

windows已有mysql的情况下 mysql8 安装

安装前先停掉本地已有的mysql服务https://dev.mysql.com/downloads/mysql/ 下载mysql压缩包解压创建 my.init 文件 [mysqld] port 3307 basedirF:\mysql-8.0.33-winx64\mysql-8.0.33-winx64 datadirF:\mysql-8.0.33-winx64\mysql-8.0.33-winx64\data max_connections200 cha…

3.3.内存的学习,pinnedmemory,内存效率问题

目录 前言1. Memory总结 前言 杜老师推出的 tensorRT从零起步高性能部署 课程&#xff0c;之前有看过一遍&#xff0c;但是没有做笔记&#xff0c;很多东西也忘了。这次重新撸一遍&#xff0c;顺便记记笔记。 本次课程学习精简 CUDA 教程-内存模型&#xff0c;pinned memory&am…

2023.7.08

#include "widget.h"void Widget::my_slot() {if((edit1->text()"admin")&&(edit2->text()"123456")){qDebug()<<"登陆成功";emit jump();close();}else{qDebug()<<"登陆失败";} }void Widget::b…

OSPFv2基础02_工作原理

目录 1.OSPF接口状态 2.OSPF邻居状态 2.1 OSPF邻居状态类型 2.2 广播网络OSPF邻接关系建立 3.Router ID&#xff08;路由器ID&#xff09;选举 4.DR和BDR选举 4.1 为什么引入DR和BDR&#xff1f; 4.2 DR和BDR的作用 4.3 DR和BDR选举过程 4.4 DR和BDR选举原则 5.OSPF路…

基于单片机指纹考勤系统的设计与实现

功能介绍 以51单片机作为主控系统&#xff1b;利用指纹采集模块存储打卡信息&#xff1b;12864显示当前考勤信息&#xff0c;时间 &#xff1b;如果迟到 语音播报 您已迟到&#xff1b;按键进行注册指纹、删除指纹、设置当前时间和签到时间、查询打卡等&#xff1b;具有掉电保存…

【YOLOv7调整detect.py】1.调整检测框粗细,2.设定标签颜色,3.只显示与标签数目相同的检测结果

目录 1. 调整检测框粗细2. 设定标签颜色3. 只显示与标签数目相同的检测结果 1. 调整检测框粗细 在detect.py中按住CtrlF检索line_thickness定位过去&#xff0c;在129行左右&#xff0c;更改line_thickness的大小即可&#xff0c;例如改为line_thickness3 2. 设定标签颜色 在…

Spring核心 and 创建使用

Spring核心 and 创建使用 文章目录 Spring核心 and 创建使用一、Spring的定义1.1什么是IoC1.1.1 理解控制反转&#xff08;IoC&#xff09;1.1.2 控制反转式程序开发 1.2 使用Spring IoC核心功能2.1 DI的概念说明 二、Spring的创建和使用2.1 创建一个Maven项目2.2 添加Spring框…

解决在jupyter notebook中找不到pip安装后的库

解决在jupyter notebook中找不到已安装的库

Todo-List案例版本二

(160条消息) Todo-List案例版本一_bubbleJessica的博客-CSDN博客 引入了localStorage&#xff0c;让案例更加完善 src/App.vue <template><div id"root"><div class"todo-container"><div class"todo-wrap"><MyHe…

pycharm 打开终端,安装第三方程序

鼠标移动到左下角 弹出列表&#xff0c;选择终端&#xff0c;当然也可以用快捷键唤出&#xff0c; 可以输入命令进行第三方库的安装

Redis实战案例14-分布式锁的基本原理、不同实现方法对比以及基于Redis进行实现思路

1. 分布式锁基本原理 基于数据库的分布式锁&#xff1a;这种方式使用数据库的特性来实现分布式锁。具体流程如下&#xff1a; 获取锁&#xff1a;当一个节点需要获得锁时&#xff0c;它尝试在数据库中插入一个特定的唯一键值&#xff08;如唯一约束的主键&#xff09;&#xff…

vue 进阶---动态组件 插槽 自定义指令

目录 动态组件 如何实现动态组件渲染 使用 keep-alive 保持状态 keep-alive 对应的生命周期函数 keep-alive 的 include 属性和exclude属性 插槽 插槽的基础用法 具名插槽 作用域插槽 自定义指令 自定义指令的分类 私有自定义指令 全局自定义指令 了解 eslint 插件…

mysql 单表查询练习

mysql 单表查询练习 创建数据表代码 CREATE TABLE emp (empno int(4) NOT NULL,ename varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,job varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,mgr int(4) NULL DEFAU…

附件上传报java.lang.RuntimeException: java.nio.file.NoSuchFileException的问题

1、报错信息 java.lang.RuntimeException: java.lang.RuntimeException: java.nio.file.NoSuchFileException: /tmp/undertow.5113172416389412561.31101/undertow1781128540461109448upload 2、原因 Java项目以java -jar命令启动后&#xff0c;进行文件上传的操作&#xff0c…

android 测试google pay

1、到GooglePlay后台创建商品&#xff0c;需要注意的是要创建商品必须先发布一个带有Billing库的aab到GooglePlay&#xff08;测试渠道即可&#xff09; 2、获取并配置好商品id之后&#xff0c;将测试用的aab发布到内部测试&#xff0c;并添加测试人员的邮箱。 3、通过连接分享…

获取系统时间日期相关接口梳理

时间&日期 ##MyTime.hpp #pragma once #include <iostream> #include <ctime> #include <string>using namespace std;class MyTime { public:MyTime() {};~MyTime() {};time_t timeSec(void);uint64_t timeMs(void);string timeDate(void); };##MyTim…

端口监控:HHD Device Monitoring Studio Crack

设备监控工作室 监控、记录和分析流经 PC 端口和连接的数据 设备监控工作室 Device Monitoring Studio 是一款高性能非侵入式软件解决方案&#xff0c;用于监控、记录和分析通过 PC 端口和连接传入的数据。 在其开发过程中&#xff0c;我们特别注重所有数据拦截和处理算法的优化…