并发式编程的相关知识--notify和wait、CompletableFuture

news2024/10/1 9:34:15

1.notify和wait方法的使用

1.1快递到站通知

说明:快递的地点在上海,离快递发货地相聚500km,每次进行改变,快递将会前进100km,当快递前进100km时,需要通知快递当前的位置,当快递到达目的地时,需要通知用户取快递。

1.Express快递初始化方法

package com.nq;

public class Express {
    public final static String DIST_CITY="ShangHai";
    public final static int TOTAIL=500;
    private int km;
    private String site;

    public Express(){

    }

    public Express(int km, String site) {
        this.km = km;
        this.site = site;
    }

    public void change(){
        if(km<TOTAIL){
           km=km+100;
            System.out.println("this Km is "+this.km);
        }

        if(km>=TOTAIL){
           site=DIST_CITY;
            System.out.println("this Express is arrived");
        }
    }

    /**
     * 线程等待公里的变化
     */
    public synchronized void waiKm(){
        while (this.km<=TOTAIL){
          try{
             wait();
              System.out.println("Map thread["+Thread.currentThread().getId()+"] wake ,I will change db");
          }catch (InterruptedException e){
             e.printStackTrace();
          }
        }
    }

    /*线程等待目的地变换*/
    public synchronized void waiSite(){
         while (!this.site.equals(DIST_CITY)){
             try {
                 wait();
                 System.out.println("Notice User thread ["+Thread.currentThread().getId()+" ] wake");
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
         }
        System.out.println("this site is "+this.site+",I will call user");
    }
}

2.TestWN测试方法

package com.nq;

public class TestWN {

    private static Express express=new Express(0,"WUHAN");


    private static class CheckKm extends Thread{
        @Override
        public void run() {
           express.waiKm();
        }
    }

    private static class CheckSite extends Thread{
        @Override
        public void run() {
            express.waiSite();
        }
    }


    public static void main(String[] args) throws InterruptedException {
        for(int i=1;i<2;i++){
            new CheckSite().start();
        }

        for (int i=0;i<2;i++){
           new CheckKm().start();
        }

        Thread.sleep(500);

        for (int i=0;i<5;i++){
           synchronized (express){
               express.change();
               express.notifyAll();
           }
            Thread.sleep(500);
        }
    }
}

在这里插入图片描述

1.2数据库连接池方法

1.SqlConnectImpl获取连接池

package com.nq.pool;

import com.nq.tool.SleepTools;

import java.sql.*;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;

/**
 *@Author: Nickel
 *@DATE: 2023/8/19 0:19
 *@Description:
 */
public class SqlConnectImpl implements Connection {

   /**
    *@Author: Nickel
    *@DATE: 2023/8/19 0:18
    *@Description:拿一个数据库链接
    */
    public static final Connection fetchConnection(){
        return new SqlConnectImpl();
    }

    public Statement createStatement() throws SQLException {
        return null;
    }

    public PreparedStatement prepareStatement(String sql) throws SQLException {
        return null;
    }

    public CallableStatement prepareCall(String sql) throws SQLException {
        return null;
    }

    public String nativeSQL(String sql) throws SQLException {
        return null;
    }

    public void setAutoCommit(boolean autoCommit) throws SQLException {

    }

    public boolean getAutoCommit() throws SQLException {
        return false;
    }

    public void commit() throws SQLException {
        SleepTools.ms(70);
    }

    public void rollback() throws SQLException {

    }

    public void close() throws SQLException {

    }

    public boolean isClosed() throws SQLException {
        return false;
    }

    public DatabaseMetaData getMetaData() throws SQLException {
        return null;
    }

    public void setReadOnly(boolean readOnly) throws SQLException {

    }

    public boolean isReadOnly() throws SQLException {
        return false;
    }

    public void setCatalog(String catalog) throws SQLException {

    }

    public String getCatalog() throws SQLException {
        return null;
    }

    public void setTransactionIsolation(int level) throws SQLException {

    }

    public int getTransactionIsolation() throws SQLException {
        return 0;
    }

    public SQLWarning getWarnings() throws SQLException {
        return null;
    }

    public void clearWarnings() throws SQLException {

    }

    public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
        return null;
    }

    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
        return null;
    }

    public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
        return null;
    }

    public Map<String, Class<?>> getTypeMap() throws SQLException {
        return null;
    }

    public void setTypeMap(Map<String, Class<?>> map) throws SQLException {

    }

    public void setHoldability(int holdability) throws SQLException {

    }

    public int getHoldability() throws SQLException {
        return 0;
    }

    public Savepoint setSavepoint() throws SQLException {
        return null;
    }

    public Savepoint setSavepoint(String name) throws SQLException {
        return null;
    }

    public void rollback(Savepoint savepoint) throws SQLException {

    }

    public void releaseSavepoint(Savepoint savepoint) throws SQLException {

    }

    public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
        return null;
    }

    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
        return null;
    }

    public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
        return null;
    }

    public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
        return null;
    }

    public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
        return null;
    }

    public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
        return null;
    }

    public Clob createClob() throws SQLException {
        return null;
    }

    public Blob createBlob() throws SQLException {
        return null;
    }

    public NClob createNClob() throws SQLException {
        return null;
    }

    public SQLXML createSQLXML() throws SQLException {
        return null;
    }

    public boolean isValid(int timeout) throws SQLException {
        return false;
    }

    public void setClientInfo(String name, String value) throws SQLClientInfoException {

    }

    public void setClientInfo(Properties properties) throws SQLClientInfoException {

    }

    public String getClientInfo(String name) throws SQLException {
        return null;
    }

    public Properties getClientInfo() throws SQLException {
        return null;
    }

    public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
        return null;
    }

    public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
        return null;
    }

    public void setSchema(String schema) throws SQLException {

    }

    public String getSchema() throws SQLException {
        return null;
    }

    public void abort(Executor executor) throws SQLException {

    }

    public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {

    }

    public int getNetworkTimeout() throws SQLException {
        return 0;
    }

    public <T> T unwrap(Class<T> iface) throws SQLException {
        return null;
    }

    public boolean isWrapperFor(Class<?> iface) throws SQLException {
        return false;
    }
}

2.DBPool初始化连接池

package com.nq.pool;

import java.sql.Connection;
import java.util.LinkedList;

public class DBPool {
    /**
     * 容器,存放链接
     */
    private static LinkedList<Connection> pool=new LinkedList<Connection>();

    /**
     * 限制连接池大小为=20
     */
    public DBPool(int initialSize){
       if(initialSize>0){
           for(int i=0;i<initialSize;i++){
               pool.addLast(SqlConnectImpl.fetchConnection());
           }
       }
    }

    /**
     *@Author: Nickel
     *@DATE: 2023/8/19 0:21
     *@Description: 释放链接,通知其他的等待连接的线程
     */
    public void releaseConnection(Connection connection){
      if(connection!=null){
         synchronized (pool){
             pool.addLast(connection);
             //通知其他等待连接的线程
             pool.notifyAll();
         }
      }
    }

    /**
     *@Author: Nickel
     *@DATE: 2023/8/19 0:26
     *@Description: 获取mills内无法获取,将会返回null 1s
     */
    public Connection fetchConnect(long mills) throws InterruptedException {
          synchronized (pool){
              //永不超时
              if(mills<=0){
                   while (pool.isEmpty()){
                        pool.wait();
                   }
                   return pool.removeFirst();
              }else{
                //超时时刻
                long future=System.currentTimeMillis()+mills;
                //等待时长
                long remaining=mills;
                while (pool.isEmpty()&&remaining>0){
                   pool.wait(remaining);
                   /*唤醒一次,重新计算等待时常*/
                   remaining=future-System.currentTimeMillis();
                }
                Connection connection=null;
                if(!pool.isEmpty()){
                    connection=pool.removeFirst();
                }
                return connection;
              }
          }
    }
}

3.测试连接池

package com.nq.pool;

import com.nq.tool.SleepTools;
import javafx.concurrent.Worker;

import java.sql.Connection;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Auther: Nickel
 * DATE: 2023/8/19 0:45
 * Description:
 * @Version 1.0
 */
public class DBPoolTest {
    static DBPool pool=new DBPool(10);
    //控制器:控制main线程将会等待所有Worker结束才能继续执行
    static CountDownLatch end;

    public static void main(String[] args) {
        //线程数量
        int threadCount=50;
        end=new CountDownLatch(threadCount);
        int count=20;//每个线程的操作次数
        AtomicInteger got=new AtomicInteger();//计数器:统计可以拿到连接的线程
        AtomicInteger notGot=new AtomicInteger();//计数器:统计没有拿到连接的线程
        for(int i=0;i<threadCount;i++){
          Thread thread=new Thread(new Worker(count,got,notGot),"worker"+i);
          thread.start();
        }
    }

    static class Worker implements Runnable{
        int count;
        AtomicInteger got;
        AtomicInteger notGot;

        public Worker(int count, AtomicInteger got, AtomicInteger notGot) {
            this.count = count;
            this.got = got;
            this.notGot = notGot;
        }

        @Override
        public void run() {
          while (count>0){
              try {
                  //从线程池中获取连接,如果1000ms内无法获取到,将会返回null
                  //分别统计连接获取的数量got和未获取的数量notGot
                  Connection connection = pool.fetchConnect(1000);
                  if(connection!=null){
                      SleepTools.ms(2);
                      pool.releaseConnection(connection);
                      got.incrementAndGet();
                  }else{
                      notGot.incrementAndGet();
                      System.out.println(Thread.currentThread().getName() + "等待超时!");
                  }
              } catch (Exception e) {
                  e.printStackTrace();
              }finally {
                  count--;
              }
          }
        }
    }
}

2. CompletableFuture方法的使用

2.1 SupplyAsync和RunAsync的使用

1.SupplyAsync方法使用

package com.nq.future;

import java.util.concurrent.*;

/**
 * @Auther: Nickel
 * DATE: 2023/8/19 23:44
 * Description:
 * @Version 1.0
 *
 * supplyAsync方法的使用
 */
public class SupplyAsync {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService= Executors.newFixedThreadPool(10);

        CompletableFuture<String> task=CompletableFuture.supplyAsync(()->{
            System.out.println(Thread.currentThread().getName());
            return "Hello";
        },executorService);

        System.out.println(task.get());
    }

    private  static void sleep(int i){
        try {
            TimeUnit.SECONDS.sleep(i);
        } catch (InterruptedException e) {
            System.out.println(e);
            e.printStackTrace();
        }
    }
}

在这里插入图片描述

2.RunAsync方法使用

package com.nq.future;

import java.util.concurrent.*;

/**
 * @Auther: Nickel
 * DATE: 2023/8/19 23:53
 * Description:
 * @Version 1.0
 */
public class RunAsync {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService= Executors.newFixedThreadPool(10);

        CompletableFuture<Void> task=CompletableFuture.runAsync(()->{
            System.out.println(Thread.currentThread().getName());
        },executorService);

        System.out.println(task.get());
    }

    private  static void sleep(int i){
        try {
            TimeUnit.SECONDS.sleep(i);
        } catch (InterruptedException e) {
            System.out.println(e);
            e.printStackTrace();
        }
    }
}

在这里插入图片描述

2.2 CompletableFuture中的then*API的使用

1.thenApply、thenApplyAsync、thenAccept

说明:在多线程执行中,任务A执行完成后才能执行任务B

package com.nq.future;

import java.util.concurrent.*;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @Auther: Nickel
 * DATE: 2023/8/20 0:03
 * Description:
 * @Version 1.0
 *
 * 任务A执行完成后执行任务B
 */
public class ThenAsync {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService= Executors.newFixedThreadPool(10);

        Supplier<String> taskA=()->{
            System.out.println("1:" + Thread.currentThread().getName());
            return "Hello";
        };

        Function<String,String> taskB=s->{
            System.out.println("2:" + Thread.currentThread().getName());
            return s+" World";
        };

        CompletableFuture<String> future1=CompletableFuture.supplyAsync(taskA,executorService);
        sleep(1);
        future1.thenApply(taskB);

        System.out.println(future1.get());
    }

    private  static void sleep(int i){
        try {
            TimeUnit.SECONDS.sleep(i);
        } catch (InterruptedException e) {
            System.out.println(e);
            e.printStackTrace();
        }
    }
}

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

2.ThenCombine

说明:表示futureA执行完成再执行futureB得到合并的结果

package com.nq.future;

import java.util.concurrent.*;

/**
 * @Auther: Nickel
 * DATE: 2023/8/20 0:32
 * Description:
 * @Version 1.0
 */
public class ThenCombine {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService= Executors.newFixedThreadPool(10);

        CompletableFuture<String> futureA=CompletableFuture.supplyAsync(()->{
            System.out.println(Thread.currentThread().getName());
            sleep(3);
            return "Hello";
        },executorService);

        CompletableFuture<String> futureB=CompletableFuture.supplyAsync(()->{
            System.out.println(Thread.currentThread().getName());
            sleep(3);
            return " World!";
        });

        CompletableFuture<String> result=futureA.thenCombine(futureB,(resultA,resultB)->{
            System.out.println(Thread.currentThread().getName());
            return resultA+resultB;
        });

        System.out.println(result.get());
    }

    private  static void sleep(int i){
        try {
            TimeUnit.SECONDS.sleep(i);
        } catch (InterruptedException e) {
            System.out.println(e);
            e.printStackTrace();
        }
    }
}

在这里插入图片描述

3.runAfterEither、runAfterBoth

说明:runAfterEither表示其中之一执行完成,返回结果,runAfterBoth表示两者都执行完成后,返回结果,而在方法futureB抛出异常,所以无法执行完成,所以runAfterBoth无法执行。

package com.nq.future;

import java.util.concurrent.*;

/**
 * @Auther: Nickel
 * DATE: 2023/8/20 0:49
 * Description:
 * @Version 1.0
 */
public class RunAfter {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService= Executors.newFixedThreadPool(10);

        CompletableFuture<String> futureA=CompletableFuture.supplyAsync(()->{
            System.out.println(Thread.currentThread().getName());
            sleep(3);
            return "Hello";
        },executorService);

        CompletableFuture<String> futureB=CompletableFuture.supplyAsync(()->{
            System.out.println(Thread.currentThread().getName());
            sleep(3);
            throw new NullPointerException();
           // return " World!";
        },executorService);


        System.out.println("-------------");
        futureB.runAfterEither(futureA,()->{
            System.out.println("!!");
        });

        System.out.println("-------------");
        futureB.runAfterBoth(futureA,()->{
            System.out.println("11111");
        });
    }

    private  static void sleep(int i){
        try {
            TimeUnit.SECONDS.sleep(i);
        } catch (InterruptedException e) {
            System.out.println(e);
            e.printStackTrace();
        }
    }
}

在这里插入图片描述

4.allOf、anyOf

说明:allOf表示futureA和futureB都执行完成才会输出,anyOf表示两者只要其中之一执行完成就会输出

package com.nq.future;

import java.util.concurrent.*;

/**
 * @Auther: Nickel
 * DATE: 2023/8/20 0:49
 * Description:
 * @Version 1.0
 */
public class AllOfAndOf {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService= Executors.newFixedThreadPool(10);

        CompletableFuture<String> futureA=CompletableFuture.supplyAsync(()->{
            System.out.println(Thread.currentThread().getName());
            sleep(5);
            return "Hello";
        },executorService);

        CompletableFuture<String> futureB=CompletableFuture.supplyAsync(()->{
            System.out.println(Thread.currentThread().getName());
            return " World!";
        },executorService);


        System.out.println("---------------");
        CompletableFuture.allOf(futureA,futureB).join();
        System.out.println("********");

        System.out.println("---------------");
        CompletableFuture.anyOf(futureA,futureB).join();
        System.out.println("11111111111");

    }

    private  static void sleep(int i){
        try {
            TimeUnit.SECONDS.sleep(i);
        } catch (InterruptedException e) {
            System.out.println(e);
            e.printStackTrace();
        }
    }
}

在这里插入图片描述

5.getNow

说明:当任务futureA休眠时,拿到的结果是getNow里面的值,当futureA不休眠时,拿到的结果是futureA的值

package com.nq.future;

import java.util.concurrent.*;

/**
 * @Auther: Nickel
 * DATE: 2023/8/20 1:09
 * Description:
 * @Version 1.0
 */
public class Now {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService= Executors.newFixedThreadPool(10);

        CompletableFuture<String> futureA=CompletableFuture.supplyAsync(()->{
            System.out.println(Thread.currentThread().getName());
            //sleep(5);
            return "Hello";
        },executorService);

        sleep(1);
        System.out.println(futureA.getNow("HaHa"));


    }

    private  static void sleep(int i){
        try {
            TimeUnit.SECONDS.sleep(i);
        } catch (InterruptedException e) {
            System.out.println(e);
            e.printStackTrace();
        }
    }
}

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

6.whenComplete、exceptionally、complete

说明:whenComplete表示有异常执行异常,没有异常,执行正常的逻辑;exceptionally只能执行异常的逻辑;complete表示休眠执行complete中的返回值,不休眠执行complete中的返回值;cancel标记执行线程,不一定真的取消

package com.nq.future;

import java.util.concurrent.*;

/**
 * @Auther: Nickel
 * DATE: 2023/8/20 1:15
 * Description:
 * @Version 1.0
 */
public class ThenComplete {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService= Executors.newFixedThreadPool(10);

        CompletableFuture<String> futureA=CompletableFuture.supplyAsync(()->{
            System.out.println(Thread.currentThread().getName());
            return "Hello";
            //throw new NullPointerException();
        },executorService);

        sleep(1);
         futureA.whenComplete((r,e)->{
            System.out.println(r);
            if(e!=null){
                e.printStackTrace();
            }
        });

        futureA.exceptionally((e)->{
            if(e!=null){
                e.printStackTrace();
            }
            return "失败";
        });

    }

    private  static void sleep(int i){
        try {
            TimeUnit.SECONDS.sleep(i);
        } catch (InterruptedException e) {
            System.out.println(e);
            e.printStackTrace();
        }
    }
}

whenComplete
在这里插入图片描述
whenComplete
在这里插入图片描述
exceptionally
在这里插入图片描述
complete
在这里插入图片描述
在这里插入图片描述
cancel
在这里插入图片描述
在这里插入图片描述

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

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

相关文章

【学习FreeRTOS】第15章——FreeRTOS队列集

1.队列集简介 一个队列只允许任务间传递的消息为同一种数据类型&#xff0c;如果需要在任务间传递不同数据类型的消息时&#xff0c;那么就可以使用队列集&#xff0c;作用&#xff1a;用于对多个队列或信号量进行“监听”&#xff0c;其中不管哪一个消息到来&#xff0c;都可…

Docker拉取并配置Grafana

Linux下安装Docker请参考&#xff1a;Linux安装Docker 安装准备 新建挂载目录 /opt/grafana/data目录&#xff0c;准备用来挂载放置grafana的数据 /opt/grafana/plugins目录&#xff0c;准备用来放置grafana的插件 /opt/grafana/config目录&#xff0c;准备用来挂载放置graf…

containerd上基于dockerfile无特权构建镜像打包工具kaniko

目录 一、kaniko是什么 二、kaniko工作原理 三、kanijo工作在Containerd上 基于serverless的考虑&#xff0c;我们选择了kaniko作为镜像打包工具&#xff0c;它是google提供了一种不需要特权就可以构建的docker镜像构建工具。 一、kaniko是什么 kaniko 是一种在容器或 Kube…

Ubuntu18.04 交叉编译curl-7.61.0

下载 官方网址是&#xff1a;curl 安装依赖库 如果需要curl支持https协议&#xff0c;需要先交叉编译 openssl,编译流程如下&#xff1a; Ubuntu18.04 交叉编译openssl-1.1.1_我是谁&#xff1f;&#xff1f;的博客-CSDN博客 解压 # 解压&#xff1a; $tar -xzvf curl-7.61.…

2023年 Java 面试八股文(25w字)

目录 一.Java 基础面试题1.Java概述Java语言有哪些特点&#xff1f;Java和C有什么关系&#xff0c;它们有什么区别&#xff1f;JVM、JRE和JDK的关系是什么&#xff1f;**什么是字节码?**采用字节码的好处是什么?Oracle JDK 和 OpenJDK 的区别是什么&#xff1f; 2.基础语法Ja…

java.lang.UnsupportedOperationException解决方法

java.lang.UnsupportedOperationException解决方法 先放错误信息业务场景报错分析先看报错代码位置进入源码查看至此 真相大白 解决方法总结 先放错误信息 业务场景 已知有学生 张三李四王五赵六 等人 private List<String> nameList Arrays.asList("张三", &…

Linux基础命令2

目录 基础命令 ln命令 grep命令 查看文本内容的五种方式 1.cat命令 2.more命令 3.less命令 4.head命令 5.tail命令 echo命令 alias命令 基础命令 ln命令 作用&#xff1a;创建链接文件 格式&#xff1a;ln 命令选项 目标文件 链接文件名 命令选项&#xff1a;-s…

jdk 03.stream

01.集合处理数据的弊端 当我们在需要对集合中的元素进行操作的时候&#xff0c;除了必需的添加&#xff0c;删除&#xff0c;获取外&#xff0c;最典型的操作就是集合遍历 package com.bobo.jdk.stream; import java.util.ArrayList; import java.util.Arrays; import java.ut…

SpringMVC拦截器介绍

1、SpringMVC拦截器 1.1 2、serlet是对目标进行干御的 3、即使路径访问成功&#xff0c;也不一定能访问的到资源&#xff0c;如果放行就能够访问到资源&#xff0c;以前只要映射关系&#xff0c;资源就能100%访问到 3.1 4、拦截器链&#xff1a;这一个个的拦截器组合到一起&…

MR混合现实实训教学系统演示

MR混合现实实训教学系统的应用场景&#xff1a; 1、汽车检测与维修 使用MR混合现实技术&#xff0c;学生可以通过虚拟头戴式设备&#xff0c;将课堂延伸到实地。例如&#xff0c;在汽车维修课程中&#xff0c;学生可以通过MR技术&#xff0c;熟悉汽车模型内部关键结构&#x…

【案例】登录注册

<template><div class"loginhome"><Header :butShow"butShow"></Header><div class"formdiv"><div style"text-align:center;padding:10px;"><h3>你好登录账号{{ stauts 3? 注册:登录 }}…

【C++】—— 简述C++11新特性

序言&#xff1a; 从本期开始&#xff0c;我将会带大家学习的是关于C11 新增的相关知识&#xff01;废话不多说&#xff0c;我们直接开始今天的学习。 目录 &#xff08;一&#xff09;C11简介 &#xff08;二&#xff09;统一的列表初始化 1、&#xff5b;&#xff5d;初始…

FreeCAD向实体填充\添加材料\镜像\制作投影

任务 在本教程中&#xff0c;您将使用零件设计工作台创建下图所示零件的 3D 实体模型。给出了完成此任务的所有必要维度。 首先从基础草图创建核心形状&#xff0c;然后在该形状的基础上进行构建&#xff0c;添加所谓的特征。 这些特征将使用附加草图和随附的特征操作向实体添…

CTFshow 限时活动 红包挑战9 详细题解

CTFshow红包挑战9 题目源码开源了。源码如下&#xff1a; common.php <?phpclass user{public $id;public $username;private $password;public function __toString(){return $this->username;}}class cookie_helper{private $secret "*************"; /…

搭建电路(最大生成树)

本文为最近做过的一道编程笔试题&#xff0c;代码实现方式多种多样&#xff0c;此处本人提供的代码可以获得正确解&#xff0c;仅供大家参考。 目录 一、题目描述二、实现代码程序三、测试结果截图 一、题目描述 题目描述&#xff1a; 明明迷上了一个搭建电路的游戏。 在游戏…

Prometheus+Grafana+AlertManager监控SpringBoot项目并发送邮件告警通知

文章目录 PrometheusGrafanaAlertManager监控平台搭建新建SpringBoot项目为Prometheus提供指标新建项目&#xff0c;引入依赖新建接口&#xff0c;运行程序 推送指标到pushgateway 开始监控Grafana连接Prometheus数据源导入Grafana模板监控SpringBoot项目 邮件告警通知同系列文…

javaee idea创建maven项目,然后创建servlet

idea创建maven项目 参考我的上一篇博客点击查看 创建servlet 步骤一 引入依赖 步骤二 新建directory并设置mark directory as 步骤三 新建package和servlet

TCP半连接队列和全连接队列

目录 什么是 TCP 半连接队列和全连接队列&#xff1f; TCP 全连接队列溢出 如何知道应用程序的 TCP 全连接队列大小&#xff1f; 如何模拟 TCP 全连接队列溢出的场景&#xff1f; 全连接队列溢出会发生什么 ? 如何增大全连接队列呢 ? TCP 半连接队列溢出 如何查看 TC…

【C#学习笔记】数据类中常用委托及接口——以List<T>为例

文章目录 List\<T\>/LinkedList \<T\>为什么是神&#xff1f;&#xff08;泛型为什么是神&#xff09;一些常见&#xff0c;通用的委托和接口ComparisonEnumerator List<T>/LinkedList <T>为什么是神&#xff1f;&#xff08;泛型为什么是神&#xff0…

STM32 进不了main 函数

1. 我用的是STM32L151C8T6 的芯片&#xff0c;在github 上找了个别人的例程&#xff0c;拿来当模板改&#xff0c;由于他用的是HSE 外部晶振&#xff0c;我用的是内部晶振HSI&#xff0c;所以需要改系统时钟&#xff0c;改完后debug&#xff0c; 一直进不了main 函数&#xff0…