Java多线程<二>多线程经典场景

leetcode 多线程刷题

  1. 上锁上一次,还是上多次?

  2. 同步的顺序。

1. 交替打印字符

  • 使用sychronize同步锁
  • 使用lock锁
  • 使用concurrent的默认机制
  • 使用volitale关键字 + Thread.sleep() / Thread.yield机制
  • 使用automic原子类

方式1 :使用互斥访问state + Number中控制当前state进行

  • 实现1:使用synchornized上锁,wait让出cpu
  • 实现2:使用semophore上锁, sleep或者yield让出cpu
  • 实现3:使用原子Integer进行访问 + yield或者sleep让出cpu
  • 实现4:使用Lock进行访问 + condition让出cpu
  • 实现5: 使用blockingQueue放入state,如果不是自己的state,在放进去,然后让出cpu。

方式2:使用互斥访问全局cur进行,cur代表当前数字是多少,如果cur >= n,就直接return让线程终止。

  • 其中cur代表的是当前的数字是多少。
  • 互斥的访问方式仍然是上面的那些种。

方式3:使用同步的通知模式

上面的方式,四个线程都是一直处于活跃状态,也就是Runnable的状态。(使用wait的除外)。另外判断是否可以运行都需要while进行判断。

但实际上,四个线程在同一时间,只需要一个线程可以运行。其他线程都必须进行阻塞。所以可以使用同步通知的方式进行,在其他线程运行的时候,阻塞另外的三个线程,并且运行完成一个线程后,可以实现精准通知另一个线程启动

2. 打印0和奇偶数字

  1. 使用锁 sychornized和Lock

  2. 使用并发工具

    • barrier

    • semopher

  3. 使用cas + Thread.sleep/volatile + ThreadSleep

  4. 使用blocking que进行实现

经典模型

1. 生产者消费者的几种实现方式

  1. 操作系统课本上的经典信号量机制。
    • 锁使用synchornized关键字
    • 加上while(true)死循环
package cn.itedus.lottery.test;


import lombok.SneakyThrows;

import java.util.Stack;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author: Zekun Fu
 * @date: 2023/11/13 11:28
 * @Description:
 */

public class test434 {
    static Stack<String> que = new Stack<>();
    static Object full = new ReentrantLock();
    static Object empty = new ReentrantLock();
    static ReentrantLock lock = new ReentrantLock();
    static int n = 0;
    static final  int st = 10;
    static class Consumer {
        void consume() {
            while (true) {
                lock.lock();
                if (n > 0) {
                    lock.unlock();
                    System.out.println("消费者消费..." + que.pop());
                    n--;
                    synchronized (full) {
                        full.notifyAll();
                    }
                } else {
                    lock.unlock();
                    synchronized (empty) {
                        try {
                            empty.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    static class Producer {
        void produce() {
            while (true) {
                lock.lock();
                if (n < st) {
                    lock.unlock();
                    String id = "" + (int)(Math.random() * 100);
                    System.out.println("生产者生产..." + id);
                    que.add(id);
                    n++;
                    synchronized (empty) {
                        empty.notifyAll();
                    }
                } else {
                    lock.unlock();
                    synchronized (full) {
                        try {
                            full.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                Producer p = new Producer();
                p.produce();
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                new Consumer().consume();
            }
        }).start();
    }
}

  1. 使用阻塞队列进行实现。 --> Java实现好的生产者消费者
  2. 手动加锁进行实现。 -->

2. 哲学家进餐

3. 读者写者

4. 并行的统计

  • 第一个例子是课本上的匹配问题。
  • 对于每一个文件夹可以使用线程池进行一个新的线程创建
  • 最后对Future进行统计
package threadBase.threadPool;

/*
*
*
*   java核心技术卷上面的线程池
* 使用线程池统计文件中含有关键字的文件个数
*  默认一个文件夹开启一个线程进行处理

 */


import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.*;

public class Test1 {
    public static void main(String[] args) {
        String dir = "D:\\projects\\java\\javaBase\\threads\\data";
        System.out.println("文件夹的绝对路径是: " + dir);
        ExecutorService pool = Executors.newCachedThreadPool();
        String keyWord = "this";
        System.out.println("关键词是: " + keyWord);
        MatchCounter counter = new MatchCounter(pool, keyWord, new File(dir));

        Future<Integer> result = pool.submit(counter);
        try {
            System.out.println("含有关键词的文件个数为:" + result.get());
        } catch (Exception e) {
            e.printStackTrace();
        }

        int largestPoolSize = ((ThreadPoolExecutor)pool).getLargestPoolSize();
        System.out.println("线程池的最大数量是:" + largestPoolSize);

        pool.shutdown();                // 别忘了关闭线程池
    }
}

class MatchCounter implements Callable<Integer> {

    private ExecutorService pool;
    private String keyWord;
    private File dir;

    public MatchCounter(ExecutorService pool, String keyWord, File dir) {
        this.pool = pool;
        this.keyWord = keyWord;
        this.dir = dir;
    }

    @Override
    public Integer call() throws Exception {
        int cnt = 0;
        try {
            File[] files = dir.listFiles();
            List<Future<Integer>> ress = new ArrayList<>();

            for (File f: files) {           // 分治
                if (f.isDirectory()) {      // 开启新线程,从线程池中
                    MatchCounter mc = new MatchCounter(pool, keyWord, f);
                    Future<Integer>res = pool.submit(mc);
                    ress.add(res);
                }
                else {                      // 如果是文件直接计算
                    if (search(f)) cnt++;
                }
            }

            for (Future<Integer>res : ress) {
                cnt += res.get();
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        return cnt;
    }
    public boolean search(File file) {
        try {
            try (Scanner sc = new Scanner(file, "UTF-8")){
                boolean flag = false;
                while(!flag && sc.hasNextLine()) {
                    String line = sc.nextLine();
                    if (line.contains(keyWord)) flag = true;
                }
                return flag;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}

5.并行的搜索

  • bfs的每一个结点开启一个新的线程进行搜索,使用并发的Map作为vis数组,使用并发的queue存入结点,同时使用并发的List放入结点。
  • 适用于请求子节点会需要大量的时间的情况,这种适合一个异步的操作。在请求的时候,对以前请求到的结点进行一个过滤和统计。
package leetcode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

/*
*
*   使用线程池 + future进行爬取
*
*
* */
public class Crawl4 {

    HashMap<String, List<String>> G = new HashMap<>();

    private class HtmlParser {
        List<String>getUrls(String start) {
            if (G.containsKey(start)) {
                List<String>ans = G.get(start);
                System.out.println("start = " + start + ", sz = "+ ans.size());
                return ans;
            }
            return new ArrayList<>();
        }
    }
    String hostName;

    private ConcurrentHashMap<String, Boolean> totalUrls = new ConcurrentHashMap<>();


    public List<String> crawl(String startUrl, HtmlParser htmlParser) {

        // bfs开始
        hostName = extractHostName(startUrl);

        ExecutorService pool = Executors.newCachedThreadPool();
        Future<List<String>>taskRes = pool.submit(new Chore(this, htmlParser, startUrl, pool));

        List<String>ans = new ArrayList<>();
        try {
            ans = taskRes.get();
        }catch (Exception e) {
            e.printStackTrace();
        }

        pool.shutdown();
        // System.out.println("最大的线程数量:" + ((ThreadPoolExecutor)pool).getLargestPoolSize());
        return ans;
    }



    private class Chore implements Callable<List<String>> {
        private Crawl4 solution;
        private HtmlParser htmlParser;
        private String urlToCrawl;
        private ExecutorService pool;

        public Chore(Crawl4 solution, HtmlParser htmlParser, String urlToCrawl, ExecutorService pool) {
            this.solution = solution;
            this.htmlParser = htmlParser;
            this.pool = pool;
            this.urlToCrawl = urlToCrawl;
        }

        @Override
        public List<String> call() throws Exception {

//            System.out.println("url = " + urlToCrawl);
            // 此处不需要使用并发的,因为统计只有主线程进行
            List<String>ans = new ArrayList<>();
            ans.add(urlToCrawl);
            this.solution.totalUrls.put(urlToCrawl, true);

            List<String> urls = htmlParser.getUrls(urlToCrawl);
            List<Future<List<String>>> ress = new ArrayList<>();

            for (String url : urls) {       // 每一个结点开启一个新的线程进行计算

                if (this.solution.totalUrls.containsKey(url)) continue;
                this.solution.totalUrls.put(url, true);

                String hostName = this.solution.extractHostName(url);
                if (!hostName.equals(this.solution.hostName)) continue;

                Chore c = new Chore(solution, htmlParser, url, pool);
                Future<List<String>> res = pool.submit(c);
                ress.add(res);
            }

            // 计算完成所有的任务,直接进行返回就行了
            for (Future<List<String>>f:ress) {
                ans.addAll(f.get());
            }
            return ans;
        }
    }

    private String extractHostName(String url) {
        String processedUrl = url.substring(7);

        int index = processedUrl.indexOf("/");
        if (index == -1) {
            return processedUrl;
        } else {
            return processedUrl.substring(0, index);
        }
    }



    public void build(int[][] edges) {
        String[] s = {"http://news.yahoo.com",
                "http://news.yahoo.com/news",
                "http://news.yahoo.com/news/topics/",
                "http://news.google.com"};


        for (int[] e : edges) {
            String u = s[e[0]];
            String v = s[e[1]];
            if (G.containsKey(u)) {
                G.get(u).add(v);
            } else {
                List<String> l = new ArrayList<>();
                l.add(v);
                G.put(u, l);
            }
        }
//        for (String t : G.get("http://news.yahoo.com/news/topics/")) {
//            System.out.println(t);
//        }
    }

    public static void main(String[] args) {
        Crawl4 c = new Crawl4();
        String input = " [[0,2],[2,1],[3,2],[3,1],[3,0],[2,0]]";
        input = input.replace("[", "{");
        input = input.replace("]", "}");
        System.out.println(input);
        int[][] edges =   {{0,2},{2,1},{3,2},{3,1},{3,0},{2,0}};
        c.build(edges);
        List<String> ans = c.crawl("http://news.yahoo.com/news/topics/", c.new HtmlParser());
        for (String s: ans) {
            System.out.println(s);
        }
    }


}

线程对效率的影响

1. 实现分治计算数组和

task放在循环外面

一个小实验,用来测试线程对性能的提升

  1. 计算数组中每一个数字乘以100的和。
  2. 使用双重循环计算,不用数学公式,这样计算时间长一点,容易做对比。
  3. 总共实现了四种不同的方式
    • 使用单线程
    • 使用4个手动写的线程
    • 使用分治,先拷贝数组分成t份,之后进行合并
    • 使用for循环生成4个手写的线程。

最后可以看到手动实现4个线程进行分治可以把效率提升到4倍左右

详细代码请看下面代码1。
在这里插入图片描述

分析1:

  • 由于我的计算机是8核16线程的,所以最多可以实现16个线程的并行计算。所以4个线程最多可以把效率提升到4倍。但是最多的效率提升就到16倍了。
  • 使用分治,由于由大量的数组拷贝,所以计算的效率会低很多。
  • 使用for循环创建线程,由于task的get()是阻塞的,会导致for循环没法执行,从而使得下面的线程没法执行。解决办法是
    • 保存生成的task, 在for循环外面调用get方法。
    • 之后的效率如下。

详细代码请看下面代码2。

在这里插入图片描述

分析2:提升线程个数带来的影响

  • 可以看到最终的效率提升了15倍左右。
  • 这是由于16个逻辑处理器并行工作的原因。
  • 这么一看电脑设计的还不错。16个逻辑处理器能并行提升15倍的性能。这还是在上下文切换的情况下。在我代码垃圾的情况下。hhhh

详细代码请看下面代码3。

在这里插入图片描述
在这里插入图片描述

代码1

package threadBase.baseKey;


import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Random;
import java.util.Stack;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.atomic.AtomicInteger;

/*
*
*
*   线程启动的三种方式
* 1. implement
* 2. extends
* 3. FutureT
*
* 4.
* */
public class StartThread {
    private static final int MAXN = 100000000;
    private static int[] nums = new int[MAXN];     // 计算数组中100个数字的和
    private AtomicInteger cur = new AtomicInteger();
    static {
        Arrays.fill(nums, 1);
    }

    private static long testSingle() throws Exception {
        long startTime = System.currentTimeMillis();
        long sum = 0;
        for (int i = 0; i < MAXN; i++) {
            for (int j = 0; j < 100; j++) {
                sum += nums[i];
            }
        }
        long endTime = System.currentTimeMillis();

        System.out.println("单线程: ");
        System.out.println("sum = " + sum + " t = " + (endTime - startTime) + "ms");

        return endTime - startTime;
    }
    private static long test1() throws Exception{


        long startTime = System.currentTimeMillis();
        FutureTask<Long> task1 = new FutureTask<Long>(() -> {
            long tsum = 0;
            for (int i = 0; i < 25000000; i++) {
                for (int j = 0; j < 100; j++) {
                    tsum += nums[i];
                }
            }
            return tsum;
        });
        FutureTask<Long> task2 = new FutureTask<Long>(() -> {
            long tsum = 0;
            for (int i = 25000000; i < 50000000; i++) {
                for (int j = 0; j < 100; j++) {
                    tsum += nums[i];
                }
            }
            return tsum;
        });
        FutureTask<Long> task3 = new FutureTask<Long>(() -> {
            long tsum = 0;
            for (int i = 50000000; i < 75000000; i++) {
                for (int j = 0; j < 100; j++) {
                    tsum += nums[i];
                }
            }
            return tsum;
        });
        FutureTask<Long> task4 = new FutureTask<Long>(() -> {
            long tsum = 0;
            for (int i = 75000000; i < 100000000; i++) {
                for (int j = 0; j < 100; j++) {
                    tsum += nums[i];
                }
            }
            return tsum;
        });
        new Thread(task1).start();
        new Thread(task2).start();
        new Thread(task3).start();
        new Thread(task4).start();
        long sum = task1.get() + task2.get() + task3.get() + task4.get();
        long endTime = System.currentTimeMillis();


        System.out.println("4线程:");
        System.out.println("sum = " + sum + " t = " + (endTime - startTime) + "ms");

        return endTime - startTime;

    }

    private static long test2() throws Exception{
        /*
         *
         *   首先需要一个线程进行任务的划分。
         *  然后由这个划分线程生成划分任务的线程数目。
         * 在有这个线程进程组装。
         * 在这使用主线程进行划分。
         * */
        int t = 5;                  // 划分线程的数量
        int len = MAXN / t;
        long sum = 0;
        long startTime = System.currentTimeMillis();
        for (int i = 0; i < t; i++) {           // 进行任务划分
            int[] numt = new int[len];
            for (int j = i * len; j < (i + 1) * len; j++) {
                numt[j - (i * len)] = nums[j];
            }
            // 线程执行
            FutureTask<Long>task = new FutureTask<Long>(()->{
                long ans = 0;
                for (int x: numt) {
                    for (int j = 0; j < 100; j++) {
                        ans += x;
                    }
                }
                return ans;
            });
            new Thread(task).start();
            sum += task.get();
        }
        long endTime = System.currentTimeMillis();

        System.out.println("使用分治进行" + t + "线程划分执行:");
        System.out.println("sum = " + sum + " t = " + (endTime - startTime) + "ms");
        return endTime - startTime;
    }

    private static long test3() throws Exception {
        StartThread startThread = new StartThread();
        int cnt = 4;                    // 控制线程的个数
        int sz = MAXN / cnt;            // 每一个线程计算的数量是多少
        long sum = 0;                        // 计算和是多少
        long startTime = System.currentTimeMillis();
        for (int i = 0; i < cnt; i++) {
            FutureTask<Long> task = new FutureTask<Long>(()->
            {
                long ans = 0L;
                int bg = startThread.cur.getAndIncrement();
                for (int j = bg * sz; j < (bg + 1) * sz; j++) {
                    for (int k = 0; k <100; k++) {
                        ans += nums[j];
                    }
                }
                return ans;
            });
            new Thread(task).start();
            sum += task.get();
        }
        long endTime = System.currentTimeMillis();
        System.out.println(cnt + "个线程:");
        System.out.println("sum = " + sum + " t = " + (endTime - startTime) + "ms");

        return endTime - startTime;
    }

    // 可以从第三遍开始,统计一个平均的时间
    public static void main(String[] args)throws Exception {

        long t1 = 0, t2 = 0, t3 = 0, t4 = 0;
        for (int i = 0; i < 11; i++) {      // 后面的8轮次进行统计
            System.out.println("-----------第" + i + "轮----------");
            if (i >= 3) {
                t1 += testSingle();
                t2 += test1();
                t3 += test2();
                t4 += test3();
            } else {
                testSingle();
                test1();
                test2();
                test3();
            }
        }
        System.out.println("平均时间:");
        System.out.println("单线程:" + t1 / 8 + "ms");
        System.out.println("4个手动多线程:" + t2 / 8 + "ms");
        System.out.println("4个分治多线程:" + t3 / 8 + "ms");
        System.out.println("for循环多线程:" + t4 / 8 + "ms");

    }
}

代码2

主要就是修改了test2和test3的方法。

  • 把task.get()放在循环外面计算。
  • 使用数组保存生成的task。
    private static long test2() throws Exception{
        /*
         *
         *   首先需要一个线程进行任务的划分。
         *  然后由这个划分线程生成划分任务的线程数目。
         * 在有这个线程进程组装。
         * 在这使用主线程进行划分。
         * */
        int t = 5;                  // 划分线程的数量
        int len = MAXN / t;
        long sum = 0;
        long startTime = System.currentTimeMillis();
        FutureTask<Long>[]tasks = new FutureTask[t];
        for (int i = 0; i < t; i++) {           // 进行任务划分
            int[] numt = new int[len];
            for (int j = i * len; j < (i + 1) * len; j++) {
                numt[j - (i * len)] = nums[j];
            }
            // 线程执行
            FutureTask<Long>task = new FutureTask<Long>(()->{
                long ans = 0;
                for (int x: numt) {
                    for (int j = 0; j < 100; j++) {
                        ans += x;
                    }
                }
                return ans;
            });
            new Thread(task).start();
            tasks[i] = task;
//            sum += task.get();            // 这个会阻塞线程,所以会慢
        }
        for (int i = 0; i < 4; i++) {
            sum += tasks[i].get();
        }
        long endTime = System.currentTimeMillis();

        System.out.println("使用分治进行" + t + "线程划分执行:");
        System.out.println("sum = " + sum + " t = " + (endTime - startTime) + "ms");
        return endTime - startTime;
    }




    public static long test4() throws Exception{
        StartThread startThread = new StartThread();
        int cnt = 4;                    // 控制线程的个数
        int sz = MAXN / cnt;            // 每一个线程计算的数量是多少
        long sum = 0;                        // 计算和是多少
        long startTime = System.currentTimeMillis();
        FutureTask<Long>[]tasks = new FutureTask[cnt];
        for (int i = 0; i < cnt; i++) {
            FutureTask<Long> task = new FutureTask<Long>(()->
            {
                long ans = 0L;
                int bg = startThread.cur.getAndIncrement();
                for (int j = bg * sz; j < (bg + 1) * sz; j++) {
                    for (int k = 0; k <100; k++) {
                        ans += nums[j];
                    }
                }
                return ans;
            });
            new Thread(task).start();
            tasks[i] = task;
        }
        for (int i = 0; i < cnt; i++) {
            sum += tasks[i].get();
        }
        long endTime = System.currentTimeMillis();
        System.out.println(cnt + "个线程:");
        System.out.println("sum = " + sum + " t = " + (endTime - startTime) + "ms");

        return endTime - startTime;
    }

代码3

  • 测试多少个线程对性能提升最大
  • 结论是逻辑处理器的个数个。
    public static void testNumOfThread() throws Exception{
        int cnt = 32;
        long []times =  new long[cnt];
        for (int i = 1; i < cnt; i++) {
            times[i] = test4(i);
        }
        for (int i = 1; i < cnt; i++) {
            System.out.println(i + "个线程:" + times[i] + "ms");
        }
    }
    // 可以从第三遍开始,统计一个平均的时间
    public static void main(String[] args)throws Exception {
        testNumOfThread();
    }

总结

  1. task.get()是阻塞的,最好不要放在主线程中,更不要放在线程创建的路径上,最好在开一个线程,进行归并。
  2. 多线程对效率的提升体现在多处理器的并行上。
  3. 这里实现的计算是平均划分数组进行求和,如果不能平均划分就会出错。应该使用归并式的那种划分。
  4. 明天实现一下多线程的归并排序多线程的斐波那契数列

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Linux上管理不同版本的 JDK

当在 Linux 上管理不同版本的 JDK 时&#xff0c;使用 yum 和 dnf 可以方便地安装和切换不同的 JDK 版本。本文将介绍如何通过这两个包管理工具安装 JDK 1.8 和 JDK 11&#xff0c;并利用软连接动态关联这些版本。 安装 JDK 1.8 和 JDK 11 使用 yum 安装 JDK 1.8 打开终端并…

Linux 内存数据 Metrics 指标解读

过去从未仔细了解过使用 free、top 等命令时显式的内存信息&#xff0c;只关注了已用内存 / 可用内存。本文我们详解解读和标注一下各个数据项的含义&#xff0c;同时和 Ganglia 显式的数据做一个映射。开始前介绍一个小知识&#xff0c;很多查看内存的命令行工具都是 cat /pro…

Pytorch框架基础

参考资料 pytorch框架基础 Pycharm 页面卡住解决方案 使用ps命令结合grep来查找PyCharm相关的进程 ps aux | grep pycharm kill -9 [PID]关于怎么找这个卡住的进程&#xff0c;据初步观察&#xff0c;卡住进程打印的信息是最长的&#xff0c;此外&#xff0c;在卡住进程的打…

贪心算法—会议安排

与其明天开始&#xff0c;不如现在行动&#xff01; 文章目录 1 安排会议1 题目描述2 解决思路3 代码实现 &#x1f48e;总结 1 安排会议 1 题目描述 一些项目要占用一个会议室宣讲&#xff0c;会议室不能同时容纳两个项目的宣讲。 给你每一个项目开始的时间和结束的时间 你来…

MendelianRandomization | 孟德尔随机化神包更新啦!~(一)(小试牛刀)

1写在前面 今天发现MendelianRandomization包更新v0.9了。&#x1f61c; 其实也算不上更新。&#x1fae0; 跟大家一起分享一下这个包做MR的用法吧。&#x1f929; 还有一个包就是TwoSampleMR&#xff0c;大家有兴趣可以去学一下。&#x1f605; 2用到的包 rm(list ls())# ins…

壮志酬筹>业务被裁>副业转正>收入回正。一个前黑马程序员老师的2023

从年初时的踌躇满志&#xff0c;到年中时整个业务线被砍。全职做前端训练营&#xff0c;四个多月的时间帮助100多名同学拿到了满意的offer&#xff0c;同时也让我的收入重归正轨。仅以这个视频记录我&#xff0c;一个普通程序员的 2023 。 视频版可直接访问 Hello&#xff0c;大…

【年度征文】回顾2023,迎接2024

转眼一年~~2023又到年底了&#xff0c;CSDN年度征文如约而至&#xff01;不知不觉又在CSDN平台写了488篇博文&#xff0c;非常感谢CSDN提供的平台&#xff0c;同时也感谢关注和支持博主的粉丝们&#xff0c;在马上到来新的一年里&#xff0c;我会继续努力&#xff01;也非常感谢…

mysql突然找不到,任务管理器里也没有了(图文详细解决)

右键开始键&#xff0c;选终端&#xff08;管理员&#xff09; 2.点↓的命令提示符&#xff0c;进到以管理员打开命令指示符 3.输入命令&#xff1a; mysqld.exe -install 如果出现这个Service successfully installed. 就代表成功了 4.输入&#xff1a; net start mysql MySO…

如何解决“电脑缺失msvcp110.dll”错误,msvcp110.dll文件解决方法

“msvcr110.dll丢失”。那么&#xff0c;msvcr110.dlll丢失到底是什么意思呢&#xff1f;它对我们的电脑有什么影响&#xff1f;本文将详细介绍msvcr110.dll的作用以及msvcr110.dll丢失对电脑的影响&#xff0c;并提供5个解决方案来解决这个问题。 一、msvcr110.dll的作用 ms…

【三维目标检测/自动驾驶】IA-BEV:基于结构先验和自增强学习的实例感知三维目标检测(AAAI 2024)

系列文章目录 论文&#xff1a;Instance-aware Multi-Camera 3D Object Detection with Structural Priors Mining and Self-Boosting Learning 地址&#xff1a;https://arxiv.org/pdf/2312.08004.pdf 来源&#xff1a;复旦大学 英特尔Shanghai Key Lab /美团 文章目录 系列文…

交互式笔记Jupyter Notebook本地部署并实现公网远程访问内网服务器

最近&#xff0c;我发现了一个超级强大的人工智能学习网站。它以通俗易懂的方式呈现复杂的概念&#xff0c;而且内容风趣幽默。我觉得它对大家可能会有所帮助&#xff0c;所以我在此分享。点击这里跳转到网站。 文章目录 1.前言2.Jupyter Notebook的安装2.1 Jupyter Notebook下…

Java guava partition方法拆分集合自定义集合拆分方法

日常开发中&#xff0c;经常遇到拆分集合处理的场景&#xff0c;现在记录2中拆分集合的方法。 1. 使用Guava包提供的集合操作工具栏 Lists.partition()方法拆分 首先&#xff0c;引入maven依赖 <dependency><groupId>com.google.guava</groupId><artifa…

Leetcode算法系列| 10. 正则表达式匹配

目录 1.题目2.题解C# 解法一&#xff1a;分段匹配法C# 解法二&#xff1a;回溯法C# 解法三&#xff1a;动态规划 1.题目 给你一个字符串 s 和一个字符规律 p&#xff0c;请你来实现一个支持 ‘.’ 和 ‘*’ 的正则表达式匹配。 1.‘.’ 匹配任意单个字符 2.‘.’ 匹配任意单个字…

SimpleCG小游戏开发系列(2)--贪吃蛇

一、前言 在之前的C语言小游戏开发系列我们已经介绍了扫雷游戏的开发&#xff0c;本篇我们继续此系列第二篇&#xff0c;同样是比较简单但好玩的一个游戏--贪吃蛇。因为有了之前的游戏框架&#xff0c;我们只需要直接搬来原来的框架即可&#xff0c;可以省去不少活。 先看看游…

布隆过滤器-使用原理和场景

一、概述 布隆过滤器&#xff08;Bloom Filter&#xff09;主要用来检索一个元素是否在一个集合中。它是一种数据结构bitMap,优点是高效的插入和查询&#xff0c;而且非常节省空间。缺点是存在误判率和删除困难。 二、应用场景 1、避免缓存穿透&#xff0c;当redis做缓…

图像的颜色及Halcon颜色空间转换transfrom_rgb/trans_to_rgb/create_color_trans lut

图像的颜色及Halcon颜色空间转换 文章目录 图像的颜色及Halcon颜色空间转换一. 图像的色彩空间1. RGB颜色 2. 灰度图像3. HSV/ HSI二. Bayer 图像三. 颜色空间的转换1. trans_from_rgb算子2. trans_to_rgb算子3. create_color_trans_lut算子 图像的颜色能真实地反映人眼所见的真…

C++的面向对象学习(7):面向对象编程的三大特性之:继承

文章目录 前言一、继承&#xff1a;继承的类除了拥有上一级类的共性&#xff0c;也拥有自己的特性。二、继承方式&#xff1a;公有继承&#xff08;public inheritance&#xff09;、私有继承&#xff08;private inheritance&#xff09;和保护继承&#xff08;protected inhe…

JavaScript基础知识点总结:从零开始学习JavaScript(六)

本章内容主要让小伙伴们自主练习 &#xff0c;建议大家先自己写出来答案&#xff0c;然后对照我的&#xff01;&#xff08;题不难主要培养自己的编程思维&#xff01;&#xff01;&#xff01;&#xff09; 如果大家感感兴趣也可以去看&#xff1a; &#x1f389;博客主页&…

matlab导出高清图片,须经修改后放入latex(例如添加文字说明,matlab画图不易操作)

一、背景 我们在写文章时&#xff0c;使用matlab画图后&#xff0c;如果不需要对图片进行额外修改或调整&#xff0c;例如添加文字说明&#xff0c;即可直接从matlab导出eps格式图片&#xff0c;然后插入到latex使用。 通常latex添加图片&#xff0c;是需要eps格式的。 但很…

两种汇编的实验

week04 一、汇编-1二、汇编-2 一、汇编-1 1 通过输入gcc -S -o main.s main.c -m32 将下面c程序”week0401学号.c“编译成汇编代码 int g(int x){ return x3; } int f(int x){ int i 学号后两位&#xff1b; return g(x)i; } int main(void){ return f(8)1; } 2. 删除汇编代码…
最新文章